forked from mindspore-Ecosystem/mindspore
!14920 clean redundant code
From: @zhao_ting_v Reviewed-by: @oacjiewen,@wuxuejian Signed-off-by: @wuxuejian
This commit is contained in:
commit
a83e31412d
|
@ -83,7 +83,6 @@ void PadCPUKernel::LaunchKernel(const std::vector<AddressPtr> &inputs, const std
|
|||
const int pad_channel_after = paddings_[1][1];
|
||||
const T pad_value = T(0);
|
||||
|
||||
// const int num = input_shape_[0];
|
||||
const int channels_orig = input_shape_[1];
|
||||
const int old_height = input_shape_[2];
|
||||
const int old_width = input_shape_[3];
|
||||
|
|
|
@ -122,7 +122,6 @@ class CenterFaceDetector():
|
|||
meta['out_height'], meta['out_width'])
|
||||
for j in range(1, self.num_classes + 1):
|
||||
dets[0][j] = np.array(dets[0][j], dtype=np.float32).reshape(-1, 15)
|
||||
# import pdb; pdb.set_trace()
|
||||
dets[0][j][:, :4] /= scale
|
||||
dets[0][j][:, 5:] /= scale
|
||||
return dets[0]
|
||||
|
@ -157,7 +156,6 @@ class CenterFaceDetector():
|
|||
if not pre_processed:
|
||||
images, meta = self.pre_process(image, scale, meta) # --1: pre_process
|
||||
else:
|
||||
# import pdb; pdb.set_trace()
|
||||
images = pre_processed_images['images'][scale][0]
|
||||
meta = pre_processed_images['meta'][scale]
|
||||
meta = {k: v.numpy()[0] for k, v in meta.items()}
|
||||
|
|
|
@ -116,10 +116,8 @@ def get_preds(pred_dir):
|
|||
"""Get preds"""
|
||||
events = os.listdir(pred_dir)
|
||||
boxes = dict()
|
||||
#pbar = tqdm.tqdm(events)
|
||||
pbar = events
|
||||
for event in pbar:
|
||||
#pbar.set_description('Reading Predictions ')
|
||||
event_dir = os.path.join(pred_dir, event)
|
||||
event_images = os.listdir(event_dir)
|
||||
current_event = dict()
|
||||
|
@ -258,7 +256,6 @@ def evaluation(pred_evaluation, gt_path, iou_thresh=0.4):
|
|||
count_face = 0
|
||||
pr_curve = np.zeros((thresh_num, 2)).astype('float')
|
||||
# [hard, medium, easy]
|
||||
# pbar = tqdm.tqdm(range(event_num)) # 61
|
||||
pbar = range(event_num)
|
||||
error_count = 0
|
||||
for i in pbar:
|
||||
|
|
|
@ -171,7 +171,6 @@ class CenterFaceLoss(nn.Cell):
|
|||
self.reg_loss = SmoothL1LossNew()
|
||||
self.reg_loss_cmask = SmoothL1LossNewCMask()
|
||||
self.print = P.Print()
|
||||
# self.reduce_sum = P.ReduceSum()
|
||||
|
||||
def construct(self, output_hm, output_wh, output_off, output_kps, hm, reg_mask, ind, wh, wight_mask, hm_offset,
|
||||
hps_mask, landmarks):
|
||||
|
@ -190,7 +189,6 @@ class CenterFaceLoss(nn.Cell):
|
|||
F.depend(loss, F.sqrt(F.cast(wight_mask, mstype.float32)))
|
||||
F.depend(loss, F.sqrt(F.cast(reg_mask, mstype.float32)))
|
||||
# add print when you want to see loss detail and do debug
|
||||
#self.print('hm_loss=', hm_loss, 'wh_loss=', wh_loss, 'off_loss=', off_loss, 'lm_loss=', lm_loss, 'loss=', loss)
|
||||
return loss
|
||||
|
||||
|
||||
|
|
|
@ -69,11 +69,9 @@ class SmoothL1LossNew(nn.Cell):
|
|||
:return:
|
||||
'''
|
||||
output = self.transpose(output, (0, 2, 3, 1))
|
||||
# dim = self.shape(output)[3]
|
||||
mask = P.Select()(P.Equal()(ind, 1), P.Fill()(mstype.float32, P.Shape()(ind), 1.0), P.Fill()(mstype.float32,
|
||||
P.Shape()(ind),
|
||||
0.0))
|
||||
# ind = self.cast(ind, mstype.float32)
|
||||
target = self.cast(target, mstype.float32)
|
||||
output = self.cast(output, mstype.float32)
|
||||
num = self.cast(self.sum(mask, ()), mstype.float32)
|
||||
|
|
|
@ -109,15 +109,12 @@ def get_param_groups(network):
|
|||
parameter_name = x.name
|
||||
if parameter_name.endswith('.bias'):
|
||||
# all bias not using weight decay
|
||||
# print('no decay:{}'.format(parameter_name))
|
||||
no_decay_params.append(x)
|
||||
elif parameter_name.endswith('.gamma'):
|
||||
# bn weight bias not using weight decay, be carefully for now x not include BN
|
||||
# print('no decay:{}'.format(parameter_name))
|
||||
no_decay_params.append(x)
|
||||
elif parameter_name.endswith('.beta'):
|
||||
# bn weight bias not using weight decay, be carefully for now x not include BN
|
||||
# print('no decay:{}'.format(parameter_name))
|
||||
no_decay_params.append(x)
|
||||
else:
|
||||
decay_params.append(x)
|
||||
|
@ -224,7 +221,6 @@ class LOGGER(logging.Logger):
|
|||
self.info('Args:')
|
||||
args_dict = vars(args)
|
||||
for key in args_dict.keys():
|
||||
# self.info('--> {}: {}'.format(key, args_dict[key]))
|
||||
self.info('--> %s', key)
|
||||
self.info('')
|
||||
|
||||
|
|
|
@ -159,7 +159,6 @@ if __name__ == "__main__":
|
|||
parallel_mode = ParallelMode.STAND_ALONE
|
||||
degree = 1
|
||||
|
||||
# context.set_auto_parallel_context(parallel_mode=parallel_mode, device_num=degree, parameter_broadcast=True, gradients_mean=True)
|
||||
# Notice: parameter_broadcast should be supported, but current version has bugs, thus been disabled.
|
||||
# To make sure the init weight on all npu is the same, we need to set a static seed in default_recurisive_init when weight initialization
|
||||
context.set_auto_parallel_context(parallel_mode=parallel_mode, gradients_mean=True, device_num=degree)
|
||||
|
|
|
@ -51,8 +51,6 @@ def get_gt_box(img_file, label_path):
|
|||
label_info = line.split(",")
|
||||
print(label_info)
|
||||
gt_boxs.append([int(label_info[0]), int(label_info[1]), int(label_info[2]), int(label_info[3])])
|
||||
#print(line)
|
||||
#print(gt_boxs)
|
||||
|
||||
return gt_boxs
|
||||
def ctpn_infer_test(dataset_path='', result_path='', label_path=''):
|
||||
|
|
|
@ -219,8 +219,6 @@ class BboxAssignSampleForRcnn(nn.Cell):
|
|||
else:
|
||||
valid_neg_index = self.logicaland(self.concat((self.check_neg_mask, unvalid_pos_index)), valid_neg_index)
|
||||
valid_neg_index = self.logicaland(valid_neg_index, self.check_neg_mask_ignore_end)
|
||||
# import pdb
|
||||
# pdb.set_trace()
|
||||
neg_index = self.reshape(neg_index, self.reshape_shape_neg)
|
||||
|
||||
valid_neg_index = self.cast(valid_neg_index, mstype.int32)
|
||||
|
|
|
@ -42,7 +42,6 @@ def _conv(in_channels, out_channels, kernel_size=3, stride=1, padding=0, pad_mod
|
|||
layers += [nn.Conv2d(in_channels, out_channels,
|
||||
kernel_size=kernel_size, stride=stride, padding=padding,
|
||||
pad_mode=pad_mode, weight_init=weights, has_bias=True, bias_init=bias_conv)]
|
||||
# layers += [nn.BatchNorm2d(out_channels)]
|
||||
return nn.SequentialCell(layers)
|
||||
|
||||
|
||||
|
@ -195,7 +194,6 @@ class Deeptext_VGG16(nn.Cell):
|
|||
self.vgg16_feature_extractor = VGG16FeatureExtraction()
|
||||
|
||||
def construct(self, img_data, img_metas, gt_bboxes, gt_labels, gt_valids):
|
||||
# f1, f2, f3, f4, f5 = self.vgg16_feature_extractor(img_data)
|
||||
_, _, _, f4, f5 = self.vgg16_feature_extractor(img_data)
|
||||
f4 = self.cast(f4, mstype.float32)
|
||||
f5 = self.cast(f5, mstype.float32)
|
||||
|
@ -306,15 +304,11 @@ class Deeptext_VGG16(nn.Cell):
|
|||
out_boxes_i = self.decode(rois, reg_logits_i)
|
||||
boxes_all += (out_boxes_i,)
|
||||
|
||||
# img_metas_all = self.split(img_metas)
|
||||
scores_all = self.split(scores)
|
||||
mask_all = self.split(self.cast(mask_logits, mstype.int32))
|
||||
|
||||
boxes_all_with_batchsize = ()
|
||||
for i in range(self.test_batch_size):
|
||||
# scale = self.split_shape(self.squeeze(img_metas_all[i]))
|
||||
# scale_h = scale[2]
|
||||
# scale_w = scale[3]
|
||||
boxes_tuple = ()
|
||||
for j in range(self.num_classes):
|
||||
boxes_tmp = self.split(boxes_all[j])
|
||||
|
|
|
@ -21,7 +21,6 @@ from mindspore.ops import operations as P
|
|||
|
||||
def _conv(in_channels, out_channels, kernel_size=3, stride=1, padding=0, pad_mode='pad'):
|
||||
"""Conv2D wrapper."""
|
||||
# shape = (out_channels, in_channels, kernel_size, kernel_size)
|
||||
weights = 'ones'
|
||||
layers = []
|
||||
layers += [nn.Conv2d(in_channels, out_channels,
|
||||
|
|
|
@ -404,7 +404,6 @@ def create_label(is_training):
|
|||
image_path = os.path.join(coco_root, data_type, file_name)
|
||||
annos = []
|
||||
for label in anno:
|
||||
# if label["utf8_string"] != '':
|
||||
bbox = label["bbox"]
|
||||
x1, x2 = bbox[0], bbox[0] + bbox[2]
|
||||
y1, y2 = bbox[1], bbox[1] + bbox[3]
|
||||
|
|
|
@ -104,10 +104,6 @@ if __name__ == '__main__':
|
|||
optimizer = RMSProp(group_params, lr, decay=cfg.rmsprop_decay, weight_decay=cfg.weight_decay,
|
||||
momentum=cfg.momentum, epsilon=cfg.opt_eps, loss_scale=cfg.loss_scale)
|
||||
|
||||
# net_with_grads = NASNetAMobileTrainOneStepWithClipGradient(net_with_loss, optimizer)
|
||||
# net_with_grads.set_train()
|
||||
# model = Model(net_with_grads)
|
||||
|
||||
# high performance
|
||||
net_with_loss.set_train()
|
||||
model = Model(net_with_loss, optimizer=optimizer)
|
||||
|
|
|
@ -91,8 +91,7 @@ def load_model(test_net, model_path):
|
|||
continue
|
||||
elif key.startswith('network'):
|
||||
param_dict_new[key[8:]] = values
|
||||
# else:
|
||||
# param_dict_new[key] = values
|
||||
|
||||
load_param_into_net(test_net, param_dict_new)
|
||||
|
||||
def preprocess(img):
|
||||
|
@ -310,11 +309,8 @@ def detect(img, network):
|
|||
orig_img_h, orig_img_w, _ = orig_img.shape
|
||||
|
||||
input_w, input_h = compute_optimal_size(orig_img, params['inference_img_size']) # 368
|
||||
# map_w, map_h = compute_optimal_size(orig_img, params['heatmap_size']) # 320
|
||||
map_w, map_h = compute_optimal_size(orig_img, params['inference_img_size'])
|
||||
|
||||
# print("image size is: ", input_w, input_h)
|
||||
|
||||
resized_image = cv2.resize(orig_img, (input_w, input_h))
|
||||
x_data = preprocess(resized_image)
|
||||
x_data = Tensor(x_data, mstype.float32)
|
||||
|
@ -388,7 +384,6 @@ def draw_person_pose(orig_img, poses):
|
|||
return canvas
|
||||
|
||||
def depreprocess(img):
|
||||
#x_data = img.astype('f')
|
||||
x_data = img[0]
|
||||
x_data += 0.5
|
||||
x_data *= 255
|
||||
|
@ -420,7 +415,6 @@ def val():
|
|||
poses, scores = detect(img, network)
|
||||
|
||||
if poses.shape[0] > 0:
|
||||
#print("got poses")
|
||||
for index, pose in enumerate(poses):
|
||||
data = dict()
|
||||
|
||||
|
@ -437,7 +431,6 @@ def val():
|
|||
print("Predict poses size is zero.", flush=True)
|
||||
img = draw_person_pose(cv2.cvtColor(img, cv2.COLOR_BGR2RGB), poses)
|
||||
|
||||
#print('Saving result into',str(img_id)+'.png...')
|
||||
save_path = os.path.join(args.output_path, str(img_id)+".png")
|
||||
cv2.imwrite(save_path, img)
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@ class txtdataset():
|
|||
if person_cnt > 0:
|
||||
annotations = valid_annotations_for_img
|
||||
if annotations is None:
|
||||
#print(img_id,'is removed')
|
||||
self.imgIds.remove(img_id)
|
||||
|
||||
def overlay_paf(self, img, paf):
|
||||
|
@ -137,7 +136,6 @@ class txtdataset():
|
|||
max_scale = min(max(max_scale, 1), params['max_scale'])
|
||||
|
||||
scale = float((max_scale - min_scale) * random.random() + min_scale)
|
||||
#scale = random.random()*1.5+0.5
|
||||
shape = (round(w * scale), round(h * scale))
|
||||
|
||||
resized_img, resized_mask, resized_poses = self.resize_data(img, ignore_mask, poses, shape)
|
||||
|
@ -145,7 +143,6 @@ class txtdataset():
|
|||
|
||||
def random_rotate_img(self, img, mask, poses):
|
||||
h, w, _ = img.shape
|
||||
# degree = (random.random() - 0.5) * 2 * params['max_rotate_degree']
|
||||
degree = np.random.randn() / 3 * params['max_rotate_degree']
|
||||
rad = degree * math.pi / 180
|
||||
center = (w / 2, h / 2)
|
||||
|
@ -473,12 +470,8 @@ class txtdataset():
|
|||
resized_img, ignore_mask, resized_poses = self.resize_data(img, ignore_mask, poses,
|
||||
shape=(self.insize, self.insize))
|
||||
|
||||
# heatmaps = self.generate_heatmaps(resized_img, resized_poses, params['heatmap_sigma'])
|
||||
# resized_heatmaps = self.resize_output(heatmaps)
|
||||
resized_heatmaps = self.generate_heatmaps_fast(resized_img, resized_poses, params['heatmap_sigma'])
|
||||
|
||||
# pafs = self.generate_pafs(resized_img, resized_poses, params['paf_sigma'])
|
||||
# resized_pafs = self.resize_output(pafs)
|
||||
resized_pafs = self.generate_pafs_fast(resized_img, resized_poses, params['paf_sigma'])
|
||||
|
||||
ignore_mask = cv2.morphologyEx(ignore_mask.astype('uint8'), cv2.MORPH_DILATE, np.ones((16, 16))).astype('bool')
|
||||
|
|
|
@ -74,8 +74,6 @@ class openpose_loss(_Loss):
|
|||
self.maxoftensor = P.ArgMaxWithValue(-1)
|
||||
|
||||
def mean_square_error(self, map1, map2, mask=None):
|
||||
# print("mask", mask)
|
||||
# import pdb; pdb.set_trace()
|
||||
if mask is None:
|
||||
mse = self.reduceMean((map1 - map2) ** 2)
|
||||
return mse
|
||||
|
@ -98,14 +96,6 @@ class openpose_loss(_Loss):
|
|||
paf_masks = F.stop_gradient(paf_masks)
|
||||
heatmap_masks = F.stop_gradient(heatmap_masks)
|
||||
for logit_paf_t, logit_heatmap_t in zip(logit_paf, logit_heatmap):
|
||||
# TEST
|
||||
# tensor1 -- tuple
|
||||
# tensor1 = self.maxoftensor(logit_paf_t)[1]
|
||||
# tensor2 = self.maxoftensor(logit_heatmap_t)[1]
|
||||
# tensor3 = self.maxoftensor(tensor1)[1]
|
||||
# tensor4 = self.maxoftensor(tensor2)[1]
|
||||
# self.print("paf",tensor3)
|
||||
# self.print("heatmaps",tensor2)
|
||||
pafs_loss_t = self.mean_square_error(logit_paf_t, gt_paf, paf_masks)
|
||||
heatmaps_loss_t = self.mean_square_error(logit_heatmap_t, gt_heatmap, heatmap_masks)
|
||||
|
||||
|
@ -125,8 +115,6 @@ class BuildTrainNetwork(nn.Cell):
|
|||
logit_pafs, logit_heatmap = self.network(input_data)
|
||||
loss, _, _ = self.criterion(logit_pafs, logit_heatmap, gt_paf, gt_heatmap, mask)
|
||||
return loss
|
||||
#loss = self.criterion(logit_pafs, logit_heatmap, gt_paf, gt_heatmap, mask)
|
||||
# return loss, heatmaps_loss, pafs_loss
|
||||
|
||||
class TrainOneStepWithClipGradientCell(nn.Cell):
|
||||
'''TrainOneStepWithClipGradientCell'''
|
||||
|
|
|
@ -88,14 +88,12 @@ class Vgg(nn.Cell):
|
|||
in_channels = 3
|
||||
for v in cfg:
|
||||
if v == 'M':
|
||||
# layers += [nn.MaxPool2d(kernel_size=2, stride=2)]
|
||||
layers += [nn.MaxPool2d(kernel_size=2, stride=2, pad_mode='same')]
|
||||
else:
|
||||
conv2d = Conv2d(in_channels=in_channels,
|
||||
out_channels=v,
|
||||
kernel_size=3,
|
||||
stride=1,
|
||||
# padding=1,
|
||||
pad_mode='same',
|
||||
has_bias=True)
|
||||
if batch_norm:
|
||||
|
|
|
@ -108,17 +108,13 @@ def get_lr(lr, lr_gamma, steps_per_epoch, max_epoch_train, lr_steps, group_size,
|
|||
def load_model(test_net, model_path):
|
||||
if model_path:
|
||||
param_dict = load_checkpoint(model_path)
|
||||
# print(type(param_dict))
|
||||
param_dict_new = {}
|
||||
for key, values in param_dict.items():
|
||||
# print('key:', key)
|
||||
if key.startswith('moment'):
|
||||
continue
|
||||
elif key.startswith('network.'):
|
||||
param_dict_new[key[8:]] = values
|
||||
|
||||
# else:
|
||||
# param_dict_new[key] = values
|
||||
load_param_into_net(test_net, param_dict_new)
|
||||
|
||||
|
||||
|
|
|
@ -144,7 +144,6 @@ def get_lr(lr_init, lr_end, lr_max, warmup_epochs, total_epochs, steps_per_epoch
|
|||
"""
|
||||
lr_each_step = []
|
||||
total_steps = int(steps_per_epoch * total_epochs)
|
||||
# warmup_steps = steps_per_epoch * warmup_epochs
|
||||
warmup_steps = warmup_epochs
|
||||
|
||||
if lr_decay_mode == 'steps':
|
||||
|
|
|
@ -406,14 +406,6 @@ def val():
|
|||
predict_result_path = detection.write_result()
|
||||
print('predict result path is {}'.format(predict_result_path))
|
||||
|
||||
|
||||
# # TEST
|
||||
# import json
|
||||
# with open('./widerface_result/predict_2020_09_08_11_07_25.json', 'r') as f:
|
||||
# result = json.load(f)
|
||||
# detection.results = result
|
||||
|
||||
|
||||
detection.get_eval_result()
|
||||
print('Eval done.')
|
||||
|
||||
|
|
|
@ -112,7 +112,6 @@ def validate(cfg, val_dataset, model, output_dir):
|
|||
if cfg.TEST.SHIFT_HEATMAP:
|
||||
output_flipped[:, :, :, 1:] = \
|
||||
output_flipped.copy()[:, :, :, 0:-1]
|
||||
# output_flipped[:, :, :, 0] = 0
|
||||
|
||||
output = (output + output_flipped) * 0.5
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ def apply_eval(eval_param_dict):
|
|||
dataset = eval_param_dict["dataset"]
|
||||
metrics_name = eval_param_dict["metrics_name"]
|
||||
index = 0 if metrics_name == "dice_coeff" else 1
|
||||
eval_score = model.eval(dataset, dataset_sink_mode=False)[metrics_name][index]
|
||||
eval_score = model.eval(dataset, dataset_sink_mode=False)["dice_coeff"][index]
|
||||
return eval_score
|
||||
|
||||
class dice_coeff(nn.Metric):
|
||||
|
|
|
@ -146,7 +146,6 @@ def _preprocess_true_boxes(true_boxes, anchors, in_shape, num_classes, max_boxes
|
|||
num_layers = anchors.shape[0] // 3
|
||||
anchor_mask = [[6, 7, 8], [3, 4, 5], [0, 1, 2]]
|
||||
true_boxes = np.array(true_boxes, dtype='float32')
|
||||
# input_shape = np.array([in_shape, in_shape], dtype='int32')
|
||||
input_shape = np.array(in_shape, dtype='int32')
|
||||
boxes_xy = (true_boxes[..., 0:2] + true_boxes[..., 2:4]) // 2.
|
||||
# trans to box center point
|
||||
|
@ -208,8 +207,6 @@ def _preprocess_true_boxes(true_boxes, anchors, in_shape, num_classes, max_boxes
|
|||
y_true[l][j, i, k, 5 + c] = 1.
|
||||
|
||||
threshold_anchor = (iou > iou_threshold)
|
||||
# print('threshold_anchor\n', threshold_anchor.shape, threshold_anchor)
|
||||
# for t, n in enumerate(best_anchor):
|
||||
for t in range(threshold_anchor.shape[0]):
|
||||
for n in range(threshold_anchor.shape[1]):
|
||||
if not threshold_anchor[t][n]:
|
||||
|
|
|
@ -292,7 +292,6 @@ def test():
|
|||
exit(1)
|
||||
|
||||
data_root = args.data_root
|
||||
# annFile = args.annFile
|
||||
|
||||
config = ConfigYOLOV4CspDarkNet53()
|
||||
if args.testing_shape:
|
||||
|
|
|
@ -91,7 +91,6 @@ class TileBeam(nn.Cell):
|
|||
# add an dim
|
||||
input_tensor = self.expand(input_tensor, 1)
|
||||
# get tile shape: [1, beam, ...]
|
||||
# shape = self.shape(input_tensor)
|
||||
tile_shape = (1,) + (self.beam_width,)
|
||||
for _ in range(len(shape) - 1):
|
||||
tile_shape = tile_shape + (1,)
|
||||
|
@ -420,7 +419,6 @@ class BeamSearchDecoder(nn.Cell):
|
|||
|
||||
# add length penalty scores
|
||||
penalty_len = self.length_penalty(state_length)
|
||||
# return penalty_len
|
||||
log_probs = self.real_div(state_log_probs, penalty_len)
|
||||
penalty_cov = C.clip_by_value(accu_attn_scores, 0.0, 1.0)
|
||||
penalty_cov = self.log(penalty_cov)
|
||||
|
|
|
@ -50,7 +50,6 @@ class PredLogProbs(nn.Cell):
|
|||
self.compute_type = compute_type
|
||||
self.dtype = dtype
|
||||
self.log_softmax = nn.LogSoftmax(axis=-1)
|
||||
# self.shape_flat_sequence_tensor = (self.batch_size * self.seq_length, self.width)
|
||||
self.cast = P.Cast()
|
||||
|
||||
def construct(self, logits):
|
||||
|
|
|
@ -56,10 +56,6 @@ def weight_variable(shape):
|
|||
Returns:
|
||||
Tensor, var.
|
||||
"""
|
||||
# scale_shape = shape
|
||||
# fan_in, fan_out = _compute_fans(scale_shape)
|
||||
# scale = 1.0 / max(1., (fan_in + fan_out) / 2.)
|
||||
# limit = math.sqrt(3.0 * scale)
|
||||
limit = 0.1
|
||||
values = np.random.uniform(-limit, limit, shape)
|
||||
return values
|
||||
|
|
|
@ -210,7 +210,6 @@ class Adam(Optimizer):
|
|||
validator.check_value_type("use_locking", use_locking, [bool], self.cls_name)
|
||||
validator.check_value_type("use_nesterov", use_nesterov, [bool], self.cls_name)
|
||||
validator.check_value_type("loss_scale", loss_scale, [float], self.cls_name)
|
||||
# validator.check_number_range("loss_scale", loss_scale, 1.0, float("inf"), Rel.INC_LEFT, self.cls_name)
|
||||
|
||||
self.beta1 = Tensor(beta1, mstype.float32)
|
||||
self.beta2 = Tensor(beta2, mstype.float32)
|
||||
|
|
|
@ -123,7 +123,6 @@ def _load_checkpoint_to_net(config, network):
|
|||
if name.endswith(".gamma"):
|
||||
param.set_data(one_weight(value.asnumpy().shape))
|
||||
elif name.endswith(".beta") or name.endswith(".bias"):
|
||||
# param.set_data(zero_weight(value.asnumpy().shape))
|
||||
if param.data.dtype == "Float32":
|
||||
param.set_data((weight_variable(value.asnumpy().shape).astype(np.float32)))
|
||||
elif param.data.dtype == "Float16":
|
||||
|
|
|
@ -64,7 +64,6 @@ class NAMLMetric:
|
|||
def update(self, predict, y_true):
|
||||
predict = predict.flatten()
|
||||
y_true = y_true.flatten()
|
||||
# predict = np.interp(predict, (predict.min(), predict.max()), (0, 1))
|
||||
self.AUC_list.append(AUC(y_true, predict))
|
||||
self.MRR_list.append(MRR(y_true, predict))
|
||||
self.nDCG5_list.append(nDCG(y_true, predict, 5))
|
||||
|
|
|
@ -117,7 +117,6 @@ class NAMLMetric:
|
|||
def update(self, predict, y_true):
|
||||
predict = predict.flatten()
|
||||
y_true = y_true.flatten()
|
||||
# predict = np.interp(predict, (predict.min(), predict.max()), (0, 1))
|
||||
self.AUC_list.append(AUC(y_true, predict))
|
||||
self.MRR_list.append(MRR(y_true, predict))
|
||||
self.nDCG5_list.append(nDCG(y_true, predict, 5))
|
||||
|
|
|
@ -65,7 +65,6 @@ def test_eval():
|
|||
|
||||
loss_net = NetWithLossClass(ncf_net)
|
||||
train_net = TrainStepWrap(loss_net)
|
||||
# train_net.set_train()
|
||||
eval_net = PredictWithSigmoid(ncf_net, topk, num_eval_neg)
|
||||
|
||||
ncf_metric = NCFMetric()
|
||||
|
|
|
@ -529,8 +529,6 @@ class DistributedSamplerOfEval:
|
|||
self._eval_batch_size = eval_batch_size
|
||||
|
||||
self._batchs_per_rank = int(math.ceil(self._eval_batches_per_epoch / rank_size))
|
||||
# self._samples_per_rank = int(math.ceil(self._batchs_per_rank * self._eval_batch_size))
|
||||
# self._total_num_samples = self._samples_per_rank * self._rank_size
|
||||
|
||||
def __iter__(self):
|
||||
indices = [(x * self._eval_users_per_batch, (x + self._rank_id + 1) * self._eval_users_per_batch)
|
||||
|
|
|
@ -201,7 +201,6 @@ class NetWithLossClass(nn.Cell):
|
|||
"""
|
||||
def __init__(self, network):
|
||||
super(NetWithLossClass, self).__init__(auto_prefix=False)
|
||||
#self.loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True)
|
||||
self.loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True)
|
||||
self.network = network
|
||||
self.reducesum = P.ReduceSum(keep_dims=False)
|
||||
|
|
|
@ -58,15 +58,11 @@ class UpsampleNetwork(nn.Cell):
|
|||
for scale in upsample_scales:
|
||||
freq_axis_padding = (freq_axis_kernel_size - 1) // 2
|
||||
k_size = (freq_axis_kernel_size, scale * 2 + 1)
|
||||
# padding = (freq_axis_padding, scale)
|
||||
padding = (freq_axis_padding, freq_axis_padding, scale, scale)
|
||||
stretch = Resize(scale, 1, mode)
|
||||
conv = nn.Conv2d(1, 1, kernel_size=k_size, has_bias=False, pad_mode='pad', padding=padding)
|
||||
up_layers.append(stretch)
|
||||
up_layers.append(conv)
|
||||
# if upsample_activation != "none":
|
||||
# nonlinear = _get_activation(upsample_activation)
|
||||
# up_layers.append(nonlinear(**upsample_activation_params))
|
||||
self.up_layers = nn.CellList(up_layers)
|
||||
|
||||
def construct(self, c):
|
||||
|
@ -86,8 +82,6 @@ class UpsampleNetwork(nn.Cell):
|
|||
# B x C x T
|
||||
c = self.squeeze_op(c)
|
||||
|
||||
# if self.indent > 0:
|
||||
# c = c[:, :, self.indent:-self.indent]
|
||||
return c
|
||||
|
||||
|
||||
|
|
|
@ -67,9 +67,6 @@ def np2Tensor(*args, rgb_range=255):
|
|||
np_transpose = np.ascontiguousarray(img.transpose((2, 0, 1)))
|
||||
tensor = np_transpose.astype(np.float32)
|
||||
tensor = tensor * (rgb_range / 255)
|
||||
# tensor = torch.from_numpy(np_transpose).float()
|
||||
# tensor.mul_(rgb_range / 255)
|
||||
|
||||
return tensor
|
||||
|
||||
return [_np2Tensor(a) for a in args]
|
||||
|
|
|
@ -159,7 +159,6 @@ class ImageFolderPKDataset:
|
|||
for idx, sample in enumerate(self.samples):
|
||||
label = sample[1]
|
||||
id2range[label].append((sample, idx))
|
||||
# print(id2range)
|
||||
for key in id2range:
|
||||
id2range[key].sort(key=lambda x: int(os.path.basename(x[0][0]).split(".")[0]))
|
||||
for item in id2range[key]:
|
||||
|
|
|
@ -93,9 +93,7 @@ if __name__ == '__main__':
|
|||
|
||||
model = Model(train_net, eval_network=test_net, metrics={"Accuracy": Accuracy()})
|
||||
|
||||
# time_cb = TimeMonitor(data_size=step_size)
|
||||
loss_cb = LossMonitor()
|
||||
#cb = [time_cb, loss_cb]
|
||||
cb = [loss_cb]
|
||||
config_ck = CheckpointConfig(save_checkpoint_steps=config.save_checkpoint_steps, \
|
||||
keep_checkpoint_max=config.keep_checkpoint_max)
|
||||
|
|
|
@ -54,12 +54,10 @@ def cmc(
|
|||
assert isinstance(gallery_ids, np.ndarray)
|
||||
# assert isinstance(query_cams, np.ndarray)
|
||||
# assert isinstance(gallery_cams, np.ndarray)
|
||||
# separate_camera_set=False
|
||||
first_match_break = True
|
||||
m, _ = distmat.shape
|
||||
# Sort and find correct matches
|
||||
indices = np.argsort(distmat, axis=1)
|
||||
#print(indices)
|
||||
matches = (gallery_ids[indices] == query_ids[:, np.newaxis])
|
||||
# Compute CMC for each query
|
||||
ret = np.zeros([m, topk])
|
||||
|
@ -174,21 +172,13 @@ def mean_ap(
|
|||
is_valid_query = np.zeros(m)
|
||||
for i in range(m):
|
||||
# Filter out the same id and same camera
|
||||
# valid = ((gallery_ids[indices[i]] != query_ids[i]) |
|
||||
# (gallery_cams[indices[i]] != query_cams[i]))
|
||||
valid = (gallery_ids[indices[i]] != query_ids[i]) | (gallery_ids[indices[i]] == query_ids[i])
|
||||
# valid = indices[i] != i
|
||||
# valid = (gallery_cams[indices[i]] != query_cams[i])
|
||||
y_true = matches[i, valid]
|
||||
y_score = -distmat[i][indices[i]][valid]
|
||||
|
||||
# y_true=y_true[0:100]
|
||||
# y_score=y_score[0:100]
|
||||
if not np.any(y_true): continue
|
||||
is_valid_query[i] = 1
|
||||
aps[i] = average_precision_score(y_true, y_score)
|
||||
# if not aps:
|
||||
# raise RuntimeError("No valid query")
|
||||
if average:
|
||||
return float(np.sum(aps)) / np.sum(is_valid_query)
|
||||
return aps, is_valid_query
|
||||
|
|
|
@ -34,7 +34,6 @@ class Angle:
|
|||
self.angle_with_H_numbers = value[4]
|
||||
self.angle_without_H_numbers = value[5]
|
||||
self.angle_numbers = self.angle_with_H_numbers + self.angle_without_H_numbers
|
||||
# print(self.angle_numbers)
|
||||
information = []
|
||||
information.extend(value)
|
||||
while count < 15:
|
||||
|
@ -108,7 +107,6 @@ class Angle:
|
|||
if "%FORMAT" in context[start_idx]:
|
||||
continue
|
||||
else:
|
||||
# print(start_idx)
|
||||
value = list(map(float, context[start_idx].strip().split()))
|
||||
information.extend(value)
|
||||
count += len(value)
|
||||
|
|
|
@ -154,7 +154,6 @@ class md_information:
|
|||
self.simulation_start_time = float(context[1].strip().split()[1])
|
||||
while count <= 6 * self.atom_numbers + 3:
|
||||
start_idx += 1
|
||||
# print(start_idx)
|
||||
value = list(map(float, context[start_idx].strip().split()))
|
||||
information.extend(value)
|
||||
count += len(value)
|
||||
|
|
|
@ -32,7 +32,6 @@ class NpyDataset():
|
|||
def __getitem__(self, item):
|
||||
data = self.data[item]
|
||||
label = self.label[item]
|
||||
# return data, label
|
||||
return data.astype(np.float32), label.astype(np.int32)
|
||||
|
||||
|
||||
|
|
|
@ -195,7 +195,6 @@ class AudioProcessor():
|
|||
sliced_foreground = padded_foreground[time_shift_offset: time_shift_offset + desired_samples]
|
||||
background_add = background_data[0] * background_volume + sliced_foreground
|
||||
background_clamp = np.clip(background_add, -1.0, 1.0)
|
||||
# feature = mfcc(background_clamp, samplerate=FLAGS.sample_rate, winlen=0.03, winstep=0.01, numcep=40, nfilt=40).flatten()
|
||||
feature = mfcc(background_clamp, samplerate=FLAGS.sample_rate, winlen=FLAGS.window_size_ms / 1000,
|
||||
winstep=FLAGS.window_stride_ms / 1000,
|
||||
numcep=FLAGS.dct_coefficient_count, nfilt=40, nfft=1024, lowfreq=20, highfreq=7000).flatten()
|
||||
|
|
|
@ -382,7 +382,6 @@ def get_ans_from_pos(tokenizer, examples, features, y1, y2, unique_id):
|
|||
tok_text = " ".join(tok_text.split())
|
||||
orig_text = " ".join(orig_tokens)
|
||||
final_text = get_final_text(tok_text, orig_text, True, False)
|
||||
# print("final_text: " + final_text)
|
||||
return final_text
|
||||
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ from mindspore.communication.management import init, get_rank
|
|||
from mindspore.train.model import Model
|
||||
from mindspore.train.callback import ModelCheckpoint, CheckpointConfig, TimeMonitor
|
||||
from mindspore.common import set_seed
|
||||
#from mindspore.profiler import Profiler
|
||||
|
||||
from src.autodis import ModelBuilder, AUCMetric
|
||||
from src.config import DataConfig, ModelConfig, TrainConfig
|
||||
|
@ -75,7 +74,6 @@ if __name__ == '__main__':
|
|||
rank_id = None
|
||||
|
||||
# Init Profiler
|
||||
#profiler = Profiler(output_path='./data', is_detail=True, is_show_op_path=False, subgraph='all')
|
||||
|
||||
ds_train = create_dataset(args_opt.dataset_path,
|
||||
train_mode=True,
|
||||
|
|
Loading…
Reference in New Issue