diff --git a/chapter04/alexnet/main.py b/chapter04/alexnet/main.py index e17d25127af11955c5f1d3f31e3a5c445356f199..698a8e730891d5d93ef44c63d06d9967d866e592 100644 --- a/chapter04/alexnet/main.py +++ b/chapter04/alexnet/main.py @@ -83,7 +83,7 @@ if __name__ == "__main__": context.set_context(mode=context.GRAPH_MODE, device_target=args.device_target) network = AlexNet(cfg.num_classes) - loss = nn.SoftmaxCrossEntropyWithLogits(is_grad=False, sparse=True, reduction="mean") + loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction="mean") repeat_size = 1 # when batch_size=32, steps is 1562 lr = Tensor(get_lr(0, cfg.learning_rate, cfg.epoch_size, 1562)) diff --git a/chapter05/resnet/resnet_cifar.py b/chapter05/resnet/resnet_cifar.py index 47f817ffdc0c4f2fe45d3e39e095142283e68ea6..e139198efe78cc6530f804ce8e25400af30a9eae 100644 --- a/chapter05/resnet/resnet_cifar.py +++ b/chapter05/resnet/resnet_cifar.py @@ -120,7 +120,7 @@ if __name__ == '__main__': epoch_size = args_opt.epoch_size net = resnet50(args_opt.num_classes) - ls = SoftmaxCrossEntropyWithLogits(sparse=True, is_grad=False, reduction="mean") + ls = SoftmaxCrossEntropyWithLogits(sparse=True, reduction="mean") opt = Momentum(filter(lambda x: x.requires_grad, net.get_parameters()), 0.01, 0.9) model = Model(net, loss_fn=ls, optimizer=opt, metrics={'acc'}) diff --git a/chapter06/lstm/eval.py b/chapter06/lstm/eval.py index 6d731fbd0dfd4e2fd3f40233e79e537dd7d0e83f..8bb139c65ca891b31829586927f13cc6669df7b7 100644 --- a/chapter06/lstm/eval.py +++ b/chapter06/lstm/eval.py @@ -64,7 +64,7 @@ if __name__ == '__main__': weight=Tensor(embedding_table), batch_size=cfg.batch_size) - loss = nn.SoftmaxCrossEntropyWithLogits(is_grad=False, sparse=True) + loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean') opt = nn.Momentum(network.trainable_params(), cfg.learning_rate, cfg.momentum) loss_cb = LossMonitor() diff --git a/chapter06/lstm/train.py b/chapter06/lstm/train.py index 53c3a89a6a33c3bb94169438c8cd2bc75e8d2d08..7fa625db04db0dcf1c6287a519604fa78bf0cb9a 100644 --- a/chapter06/lstm/train.py +++ b/chapter06/lstm/train.py @@ -70,7 +70,7 @@ if __name__ == '__main__': if args.pre_trained: load_param_into_net(network, load_checkpoint(args.pre_trained)) - loss = nn.SoftmaxCrossEntropyWithLogits(is_grad=False, sparse=True) + loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean') opt = nn.Momentum(network.trainable_params(), cfg.learning_rate, cfg.momentum) loss_cb = LossMonitor()