当前位置: 首页>>代码示例>>Python>>正文


Python functions.resize_images方法代码示例

本文整理汇总了Python中chainer.functions.resize_images方法的典型用法代码示例。如果您正苦于以下问题:Python functions.resize_images方法的具体用法?Python functions.resize_images怎么用?Python functions.resize_images使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chainer.functions的用法示例。


在下文中一共展示了functions.resize_images方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def setUp(self):

        class Model(chainer.Chain):

            def __init__(self, ops, args, input_argname):
                super(Model, self).__init__()
                self.ops = ops
                self.args = args
                self.input_argname = input_argname

            def __call__(self, x):
                self.args[self.input_argname] = x
                return self.ops(**self.args)

        # (batch, channel, height, width) = (1, 1, 2, 2)
        self.x = np.array([[[[64, 32], [64, 32]]]], np.float32)

        # 2x upsampling
        args = {'output_shape': (4, 4)}
        self.model = Model(F.resize_images, args, 'x') 
开发者ID:chainer,项目名称:chainer,代码行数:22,代码来源:test_arrays.py

示例2: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def forward(self, imgs, labels):
        h_aux, h_main = self.model.extractor(imgs)
        h_aux = F.dropout(self.aux_conv1(h_aux), ratio=0.1)
        h_aux = self.aux_conv2(h_aux)
        h_aux = F.resize_images(h_aux, imgs.shape[2:])

        h_main = self.model.ppm(h_main)
        h_main = F.dropout(self.model.head_conv1(h_main), ratio=0.1)
        h_main = self.model.head_conv2(h_main)
        h_main = F.resize_images(h_main, imgs.shape[2:])

        aux_loss = F.softmax_cross_entropy(h_aux, labels)
        main_loss = F.softmax_cross_entropy(h_main, labels)
        loss = 0.4 * aux_loss + main_loss

        chainer.reporter.report({'loss': loss}, self)
        return loss 
开发者ID:chainer,项目名称:chainercv,代码行数:19,代码来源:train_multi.py

示例3: _multiscale_predict

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def _multiscale_predict(predict_method, img, scales):
    orig_H, orig_W = img.shape[1:]
    scores = []
    orig_img = img
    for scale in scales:
        img = orig_img.copy()
        if scale != 1.0:
            img = transforms.resize(
                img, (int(orig_H * scale), int(orig_W * scale)))
        # This method should return scores
        y = predict_method(img)[None]
        assert y.shape[2:] == img.shape[1:]

        if scale != 1.0:
            y = F.resize_images(y, (orig_H, orig_W)).array
        scores.append(y)
    xp = chainer.backends.cuda.get_array_module(scores[0])
    scores = xp.stack(scores)
    return scores.mean(0)[0]  # (C, H, W) 
开发者ID:chainer,项目名称:chainercv,代码行数:21,代码来源:pspnet.py

示例4: render

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def render(directory, elevation=30, distance=DISTANCE):
    for azimuth in range(0, 360, 15):
        filename = os.path.join(directory, 'e%03d_a%03d.png' % (elevation, azimuth))
        set_camera_location(elevation, azimuth, distance)
        bpy.context.scene.render.filepath = filename
        bpy.ops.render.render(write_still=True)

        if False:
            img = scipy.misc.imread(filename)[:, :, :].astype('float32') / 255.
            if False:
                img = (img[::2, ::2] + img[1::2, ::2] + img[::2, 1::2] + img[1::2, 1::2]) / 4.
            else:
                import chainer.functions as cf
                img = img.transpose((2, 0, 1))[None, :, :, :]
                img = cf.resize_images(img, (64, 64))
                img = img[0].data.transpose((1, 2, 0))

            img = (img * 255).clip(0., 255.).astype('uint8')
            scipy.misc.imsave(filename, img) 
开发者ID:hiroharu-kato,项目名称:mesh_reconstruction,代码行数:21,代码来源:render.py

示例5: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def forward(self, x):
        y1 = F.resize_images(x, (257, 513))
        return y1


# ====================================== 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:8,代码来源:ResizeImages.py

示例6: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def __call__(self, x, out_size):
        x = self.conv1(x)
        x = self.dropout(x)
        x = self.conv2(x)
        x = F.resize_images(x, output_shape=out_size)
        return x 
开发者ID:osmr,项目名称:imgclsmob,代码行数:8,代码来源:deeplabv3.py

示例7: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def __call__(self, x):
        out_size = self.out_size if (self.out_size is not None) else\
            (x.shape[2] * self.scale_factor, x.shape[3] * self.scale_factor)
        return F.resize_images(x, output_shape=out_size) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:6,代码来源:sinet.py

示例8: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def __call__(self, x):
        return F.resize_images(x, output_shape=self.size) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:4,代码来源:resattnet.py

示例9: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def __call__(self, x):
        input_shape = x.shape
        x = self.conv1(x)
        x = self.pool(x)
        x = self.conv2(x)
        x = F.resize_images(x, output_shape=input_shape[2:])
        x = self.conv3(x)
        x = F.sigmoid(x)
        return x 
开发者ID:osmr,项目名称:imgclsmob,代码行数:11,代码来源:airnet.py

示例10: __call__

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def __call__(self, x):
        raw_pre_features = self.backbone(x)

        rpn_score = self.navigator_unit(raw_pre_features)
        rpn_score.to_cpu()
        all_cdds = [np.concatenate((y.reshape(-1, 1), self.edge_anchors.copy()), axis=1)
                    for y in rpn_score.array]
        top_n_cdds = [hard_nms(y, top_n=self.top_n, iou_thresh=0.25) for y in all_cdds]
        top_n_cdds = np.array(top_n_cdds)
        top_n_index = top_n_cdds[:, :, -1].astype(np.int64)
        top_n_index = np.array(top_n_index, dtype=np.int64)
        top_n_prob = np.take_along_axis(rpn_score.array, top_n_index, axis=1)

        batch = x.shape[0]
        x_pad = F.pad(x, pad_width=self.pad_width, mode="constant", constant_values=0)
        part_imgs = []
        for i in range(batch):
            for j in range(self.top_n):
                y0, x0, y1, x1 = tuple(top_n_cdds[i][j, 1:5].astype(np.int64))
                x_res = F.resize_images(
                    x_pad[i:i + 1, :, y0:y1, x0:x1],
                    output_shape=(224, 224))
                part_imgs.append(x_res)
        part_imgs = F.concat(tuple(part_imgs), axis=0)
        part_features = self.backbone_tail(self.backbone(part_imgs))

        part_feature = part_features.reshape((batch, self.top_n, -1))
        part_feature = part_feature[:, :self.num_cat, :]
        part_feature = part_feature.reshape((batch, -1))

        raw_features = self.backbone_tail(raw_pre_features)

        concat_out = F.concat((part_feature, raw_features), axis=1)
        concat_logits = self.concat_net(concat_out)

        if self.aux:
            raw_logits = self.backbone_classifier(raw_features)
            part_logits = self.partcls_net(part_features).reshape((batch, self.top_n, -1))
            return concat_logits, raw_logits, part_logits, top_n_prob
        else:
            return concat_logits 
开发者ID:osmr,项目名称:imgclsmob,代码行数:43,代码来源:ntsnet_cub.py

示例11: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def forward(self, inputs, device):
        x, = inputs
        output_shape = self.in_shape[2:]
        y = functions.resize_images(
            x, output_shape,
            mode=self.mode, align_corners=self.align_corners)
        return y, 
开发者ID:chainer,项目名称:chainer,代码行数:9,代码来源:test_resize_images.py

示例12: check_forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def check_forward(self, x, output_shape):
        y = functions.resize_images(x, output_shape)
        testing.assert_allclose(y.data, self.out) 
开发者ID:chainer,项目名称:chainer,代码行数:5,代码来源:test_resize_images.py

示例13: check_backward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def check_backward(self, x, output_shape, gy):
        def f(x):
            return functions.resize_images(
                x, output_shape,
                mode=self.mode, align_corners=self.align_corners)

        gradient_check.check_backward(
            f, x, gy, dtype='d', atol=1e-2, rtol=1e-3, eps=1e-5) 
开发者ID:chainer,项目名称:chainer,代码行数:10,代码来源:test_resize_images.py

示例14: forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def forward(self, x):
        ys = [x]
        H, W = x.shape[2:]
        for f, ksize in zip(self, self.ksizes):
            y = F.average_pooling_2d(x, ksize, ksize)
            y = f(y)
            y = F.resize_images(y, (H, W))
            ys.append(y)
        return F.concat(ys, axis=1) 
开发者ID:chainer,项目名称:chainercv,代码行数:11,代码来源:pspnet.py

示例15: _get_proba

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import resize_images [as 别名]
def _get_proba(self, img, scale, flip):
        if flip:
            img = img[:, :, ::-1]

        _, H, W = img.shape
        if scale == 1.0:
            h, w = H, W
        else:
            h, w = int(H * scale), int(W * scale)
            img = resize(img, (h, w))

        img = self.prepare(img)

        x = chainer.Variable(self.xp.asarray(img[np.newaxis]))
        x = self.forward(x)
        x = F.softmax(x, axis=1)
        score = F.resize_images(x, img.shape[1:])[0, :, :h, :w].array
        score = chainer.backends.cuda.to_cpu(score)

        if scale != 1.0:
            score = resize(score, (H, W))

        if flip:
            score = score[:, :, ::-1]

        return score 
开发者ID:chainer,项目名称:chainercv,代码行数:28,代码来源:deeplab_v3_plus.py


注:本文中的chainer.functions.resize_images方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。