本文整理汇总了Python中network.np_to_variable方法的典型用法代码示例。如果您正苦于以下问题:Python network.np_to_variable方法的具体用法?Python network.np_to_variable怎么用?Python network.np_to_variable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network
的用法示例。
在下文中一共展示了network.np_to_variable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __index__
# 需要导入模块: import network [as 别名]
# 或者: from network import np_to_variable [as 别名]
def __index__(self, i):
'''bid: image index; pid: patch index, to find slice'''
bid, pid = self.patch_list[i]
transform_img = []
transform_den = []
transform_raw = []
transform_raw.append(transforms.Lambda(lambda img: i_crop(img, self.patches[bid][pid], self.crop_size)))
transform_raw.append(transforms.Lambda(lambda img: i_flip(img, self.filps[i])))
transform_raw.append(transforms.Lambda(lambda img: np.array(img)))
transform_raw = transforms.Compose(transform_raw)
transform_img.append(transforms.Lambda(lambda img: i_crop(img, self.patches[bid][pid], self.crop_size)))
transform_img.append(transforms.Lambda(lambda img: i_flip(img, self.filps[i])))
transform_img += [ transforms.ToTensor(),
transforms.Normalize([0.485,0.456,0.406],[0.229,0.224,0.225])
]
transform_img = transforms.Compose(transform_img)
transform_den.append(transforms.Lambda(lambda img: d_crop(img, self.patches[bid][pid], self.crop_size)))
transform_den.append(transforms.Lambda(lambda img: d_flip(img, self.filps[i])))
transform_den += [transforms.Lambda(lambda den: network.np_to_variable(den, is_cuda=False, is_training=self.training))]
transform_den = transforms.Compose(transform_den)
img, den, gt_count = self.dataloader[bid]
return transform_img(img.copy()), transform_den(den), transform_raw(img.copy()), gt_count, i
示例2: forward
# 需要导入模块: import network [as 别名]
# 或者: from network import np_to_variable [as 别名]
def forward(self, im_data, gt_data=None):
im_data = network.np_to_variable(im_data, is_cuda=True, is_training=self.training)
density_map = self.DME(im_data)
if self.training:
gt_data = network.np_to_variable(gt_data, is_cuda=True, is_training=self.training)
self.loss_mse = self.build_loss(density_map, gt_data)
return density_map
示例3: forward
# 需要导入模块: import network [as 别名]
# 或者: from network import np_to_variable [as 别名]
def forward(self, im_data, gt_data=None, gt_cls_label=None, ce_weights=None):
im_data = network.np_to_variable(im_data, is_cuda=True, is_training=self.training)
density_map, density_cls_score = self.CCN(im_data)
density_cls_prob = F.softmax(density_cls_score)
if self.training:
gt_data = network.np_to_variable(gt_data, is_cuda=True, is_training=self.training)
gt_cls_label = network.np_to_variable(gt_cls_label, is_cuda=True, is_training=self.training,dtype=torch.FloatTensor)
self.loss_mse, self.cross_entropy = self.build_loss(density_map, density_cls_prob, gt_data, gt_cls_label, ce_weights)
return density_map
示例4: forward
# 需要导入模块: import network [as 别名]
# 或者: from network import np_to_variable [as 别名]
def forward(self, im_data, gt_data=None):
im_data = network.np_to_variable(im_data, is_cuda=True, is_training=self.training)
density_map = self.DME(im_data)
if self.training:
gt_data = network.np_to_variable(gt_data, is_cuda=True, is_training=self.training)
self.loss_mse = self.build_loss(density_map, gt_data)
return density_map
示例5: forward
# 需要导入模块: import network [as 别名]
# 或者: from network import np_to_variable [as 别名]
def forward(self, im_data, im_info, gt_boxes=None, gt_ishard=None, dontcare_areas=None):
im_data = network.np_to_variable(im_data, is_cuda=True)
im_data = im_data.permute(0, 3, 1, 2)
features = self.features(im_data)
rpn_conv1 = self.conv1(features)
# rpn score
rpn_cls_score = self.score_conv(rpn_conv1)
rpn_cls_score_reshape = self.reshape_layer(rpn_cls_score, 2)
rpn_cls_prob = F.softmax(rpn_cls_score_reshape)
rpn_cls_prob_reshape = self.reshape_layer(rpn_cls_prob, len(self.anchor_scales)*3*2)
# rpn boxes
rpn_bbox_pred = self.bbox_conv(rpn_conv1)
# proposal layer
cfg_key = 'TRAIN' if self.training else 'TEST'
rois = self.proposal_layer(rpn_cls_prob_reshape, rpn_bbox_pred, im_info,
cfg_key, self._feat_stride, self.anchor_scales)
# generating training labels and build the rpn loss
if self.training:
assert gt_boxes is not None
rpn_data = self.anchor_target_layer(rpn_cls_score, gt_boxes, gt_ishard, dontcare_areas,
im_info, self._feat_stride, self.anchor_scales)
self.cross_entropy, self.loss_box = self.build_loss(rpn_cls_score_reshape, rpn_bbox_pred, rpn_data)
return features, rois
示例6: proposal_layer
# 需要导入模块: import network [as 别名]
# 或者: from network import np_to_variable [as 别名]
def proposal_layer(rpn_cls_prob_reshape, rpn_bbox_pred, im_info, cfg_key, _feat_stride, anchor_scales):
rpn_cls_prob_reshape = rpn_cls_prob_reshape.data.cpu().numpy()
rpn_bbox_pred = rpn_bbox_pred.data.cpu().numpy()
x = proposal_layer_py(rpn_cls_prob_reshape, rpn_bbox_pred, im_info, cfg_key, _feat_stride, anchor_scales)
x = network.np_to_variable(x, is_cuda=True)
return x.view(-1, 5)
示例7: anchor_target_layer
# 需要导入模块: import network [as 别名]
# 或者: from network import np_to_variable [as 别名]
def anchor_target_layer(rpn_cls_score, gt_boxes, gt_ishard, dontcare_areas, im_info, _feat_stride, anchor_scales):
"""
rpn_cls_score: for pytorch (1, Ax2, H, W) bg/fg scores of previous conv layer
gt_boxes: (G, 5) vstack of [x1, y1, x2, y2, class]
gt_ishard: (G, 1), 1 or 0 indicates difficult or not
dontcare_areas: (D, 4), some areas may contains small objs but no labelling. D may be 0
im_info: a list of [image_height, image_width, scale_ratios]
_feat_stride: the downsampling ratio of feature map to the original input image
anchor_scales: the scales to the basic_anchor (basic anchor is [16, 16])
----------
Returns
----------
rpn_labels : (1, 1, HxA, W), for each anchor, 0 denotes bg, 1 fg, -1 dontcare
rpn_bbox_targets: (1, 4xA, H, W), distances of the anchors to the gt_boxes(may contains some transform)
that are the regression objectives
rpn_bbox_inside_weights: (1, 4xA, H, W) weights of each boxes, mainly accepts hyper param in cfg
rpn_bbox_outside_weights: (1, 4xA, H, W) used to balance the fg/bg,
beacuse the numbers of bgs and fgs mays significiantly different
"""
rpn_cls_score = rpn_cls_score.data.cpu().numpy()
rpn_labels, rpn_bbox_targets, rpn_bbox_inside_weights, rpn_bbox_outside_weights = \
anchor_target_layer_py(rpn_cls_score, gt_boxes, gt_ishard, dontcare_areas, im_info, _feat_stride, anchor_scales)
rpn_labels = network.np_to_variable(rpn_labels, is_cuda=True, dtype=torch.LongTensor)
rpn_bbox_targets = network.np_to_variable(rpn_bbox_targets, is_cuda=True)
rpn_bbox_inside_weights = network.np_to_variable(rpn_bbox_inside_weights, is_cuda=True)
rpn_bbox_outside_weights = network.np_to_variable(rpn_bbox_outside_weights, is_cuda=True)
return rpn_labels, rpn_bbox_targets, rpn_bbox_inside_weights, rpn_bbox_outside_weights
示例8: proposal_target_layer
# 需要导入模块: import network [as 别名]
# 或者: from network import np_to_variable [as 别名]
def proposal_target_layer(rpn_rois, gt_boxes, gt_ishard, dontcare_areas, num_classes):
"""
----------
rpn_rois: (1 x H x W x A, 5) [0, x1, y1, x2, y2]
gt_boxes: (G, 5) [x1 ,y1 ,x2, y2, class] int
# gt_ishard: (G, 1) {0 | 1} 1 indicates hard
dontcare_areas: (D, 4) [ x1, y1, x2, y2]
num_classes
----------
Returns
----------
rois: (1 x H x W x A, 5) [0, x1, y1, x2, y2]
labels: (1 x H x W x A, 1) {0,1,...,_num_classes-1}
bbox_targets: (1 x H x W x A, K x4) [dx1, dy1, dx2, dy2]
bbox_inside_weights: (1 x H x W x A, Kx4) 0, 1 masks for the computing loss
bbox_outside_weights: (1 x H x W x A, Kx4) 0, 1 masks for the computing loss
"""
rpn_rois = rpn_rois.data.cpu().numpy()
rois, labels, bbox_targets, bbox_inside_weights, bbox_outside_weights = \
proposal_target_layer_py(rpn_rois, gt_boxes, gt_ishard, dontcare_areas, num_classes)
# print labels.shape, bbox_targets.shape, bbox_inside_weights.shape
rois = network.np_to_variable(rois, is_cuda=True)
labels = network.np_to_variable(labels, is_cuda=True, dtype=torch.LongTensor)
bbox_targets = network.np_to_variable(bbox_targets, is_cuda=True)
bbox_inside_weights = network.np_to_variable(bbox_inside_weights, is_cuda=True)
bbox_outside_weights = network.np_to_variable(bbox_outside_weights, is_cuda=True)
return rois, labels, bbox_targets, bbox_inside_weights, bbox_outside_weights