本文整理汇总了Python中mxnet.ndarray.clip方法的典型用法代码示例。如果您正苦于以下问题:Python ndarray.clip方法的具体用法?Python ndarray.clip怎么用?Python ndarray.clip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mxnet.ndarray
的用法示例。
在下文中一共展示了ndarray.clip方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tensor_save_rgbimage
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import clip [as 别名]
def tensor_save_rgbimage(img, filename, cuda=False):
img = F.clip(img, 0, 255).asnumpy()
img = img.transpose(1, 2, 0).astype('uint8')
img = Image.fromarray(img)
img.save(filename)
示例2: imagenet_clamp_batch
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import clip [as 别名]
def imagenet_clamp_batch(batch, low, high):
""" Not necessary in practice """
F.clip(batch[:,0,:,:],low-123.680, high-123.680)
F.clip(batch[:,1,:,:],low-116.779, high-116.779)
F.clip(batch[:,2,:,:],low-103.939, high-103.939)
示例3: get_rmse_log
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import clip [as 别名]
def get_rmse_log(net, X_train, y_train):
"""Gets root mse between the logarithms of the prediction and the truth."""
num_train = X_train.shape[0]
clipped_preds = nd.clip(net(X_train), 1, float('inf'))
return np.sqrt(2 * nd.sum(square_loss(
nd.log(clipped_preds), nd.log(y_train))).asscalar() / num_train)
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:8,代码来源:kaggle_k_fold_cross_validation.py
示例4: unsorted_1d_segment_mean
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import clip [as 别名]
def unsorted_1d_segment_mean(input, seg_id, n_segs, dim):
# TODO: support other dimensions
assert dim == 0, 'MXNet only supports segment mean on first dimension'
n_ones = nd.ones_like(seg_id).astype(input.dtype)
w = unsorted_1d_segment_sum(n_ones, seg_id, n_segs, 0)
w = nd.clip(w, a_min=1, a_max=np.inf)
y = unsorted_1d_segment_sum(input, seg_id, n_segs, dim)
y = y / w.reshape((-1,) + (1,) * (y.ndim - 1))
return y
示例5: forward
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import clip [as 别名]
def forward(self, in_data):
feat_shape = in_data.shape[1:]
out_data = nd.empty((self.out_size,) + feat_shape,
ctx=in_data.context, dtype=in_data.dtype)
in_data_nd = zerocopy_to_dgl_ndarray(in_data)
out_data_nd = zerocopy_to_dgl_ndarray_for_write(out_data)
K.copy_reduce(
self.reducer if self.reducer != 'mean' else 'sum',
self.graph, self.target, in_data_nd, out_data_nd,
self.in_map[0], self.out_map[0])
# normalize if mean reducer
# NOTE(zihao): this is a temporary hack and we should have better solution in the future.
if self.reducer == 'mean':
in_ones = nd.ones((in_data.shape[0],),
ctx=in_data.context, dtype=in_data.dtype)
degs = nd.empty((out_data.shape[0],),
ctx=out_data.context, dtype=out_data.dtype)
in_ones_nd = zerocopy_to_dgl_ndarray(in_ones)
degs_nd = zerocopy_to_dgl_ndarray(degs)
K.copy_reduce(
'sum', self.graph, self.target, in_ones_nd, degs_nd,
self.in_map[0], self.out_map[0])
# reshape
degs = degs.reshape((out_data.shape[0],) + (1,) * (out_data.ndim - 1)).clip(1, float('inf'))
out_data = out_data / degs
else:
degs = None
self.save_for_backward(in_data_nd, out_data_nd, degs)
return out_data
示例6: plot_img
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import clip [as 别名]
def plot_img(losses_log):
sw.add_image(tag='lr_img', image=nd.clip(nd.concatenate(losses_log['lr_img'])[0:4], 0, 1))
sw.add_image(tag='hr_img', image=nd.clip(nd.concatenate(losses_log['hr_img'])[0:4], 0, 1))
sw.add_image(tag='hr_img_fake', image=nd.clip(nd.concatenate(losses_log['hr_img_fake'])[0:4], 0, 1))
示例7: plot_img
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import clip [as 别名]
def plot_img(losses_log):
sw.add_image(tag='A', image=nd.clip(nd.concatenate([losses_log['real_A'][0][0:1],
losses_log['fake_B'][0][0:1],
losses_log['rec_A'][0][0:1],
losses_log['idt_A'][0][0:1]]) * 0.5 + 0.5, 0, 1))
sw.add_image(tag='B', image=nd.clip(nd.concatenate([losses_log['real_B'][0][0:1],
losses_log['fake_A'][0][0:1],
losses_log['rec_B'][0][0:1],
losses_log['idt_B'][0][0:1]]) * 0.5 + 0.5, 0, 1))
示例8: hybrid_forward
# 需要导入模块: from mxnet import ndarray [as 别名]
# 或者: from mxnet.ndarray import clip [as 别名]
def hybrid_forward(self, F, x, weight):
x_norm = F.L2Normalization(x, mode='instance', name='x_n')
w_norm = F.L2Normalization(weight, mode='instance', name='w_n')
cos_theta = F.FullyConnected(x_norm, w_norm, no_bias=True, num_hidden=self._units, name='cos_theta')
cos_theta = F.clip(cos_theta, a_min=-1, a_max=1)
return cos_theta