!914 remove rescale op in dataset and add fp16 flag in eval

Merge pull request !914 from wandongdong/master
This commit is contained in:
mindspore-ci-bot 2020-05-06 11:20:49 +08:00 committed by Gitee
commit 430dbf9158
3 changed files with 5 additions and 3 deletions

View File

@ -63,7 +63,7 @@ def create_dataset(dataset_path, do_train, repeat_num=1, batch_size=32):
if do_train:
trans = [resize_crop_op, horizontal_flip_op, rescale_op, normalize_op, change_swap_op]
else:
trans = [decode_op, resize_op, center_crop, rescale_op, normalize_op, change_swap_op]
trans = [decode_op, resize_op, center_crop, normalize_op, change_swap_op]
type_cast_op = C2.TypeCast(mstype.int32)

View File

@ -24,6 +24,7 @@ from mindspore.model_zoo.mobilenet import mobilenet_v2
from mindspore.train.model import Model
from mindspore.train.serialization import load_checkpoint, load_param_into_net
from mindspore.nn.loss import SoftmaxCrossEntropyWithLogits
from mindspore.common import dtype as mstype
parser = argparse.ArgumentParser(description='Image classification')
parser.add_argument('--checkpoint_path', type=str, default=None, help='Checkpoint file path')
@ -39,7 +40,8 @@ context.set_context(enable_mem_reuse=True)
if __name__ == '__main__':
loss = SoftmaxCrossEntropyWithLogits(is_grad=False, sparse=True, reduction='mean')
net = mobilenet_v2()
net = mobilenet_v2(num_classes=config.num_classes)
net.to_float(mstype.float16)
dataset = create_dataset(dataset_path=args_opt.dataset_path, do_train=False, batch_size=config.batch_size)
step_size = dataset.get_dataset_size()

View File

@ -151,7 +151,7 @@ if __name__ == '__main__':
epoch_size = config.epoch_size
net = mobilenet_v2(num_classes=config.num_classes)
net.add_flags_recursive(fp16=True)
net.to_float(mstype.float16)
for _, cell in net.cells_and_names():
if isinstance(cell, nn.Dense):
cell.add_flags_recursive(fp32=True)