Res2Net200_vd_26w_4s 模型使用报错 'UnicodeEncodeError: 'ascii' codec can't encode character '\x90' in position 3: ordinal not in range(128)'
Created by: XiminLin
在使用 PaddleCV/image_classification/models/res2net_vd.py 里面的 Res2Net200_vd_26w_4s 模型是报错.
Traceback (most recent call last): File "classification/train_cls.py", line 180, in <module> train_cls(settings) File "classification/train_cls.py", line 53, in train_cls opt.minimize(avg_train_loss) File "<decorator-gen-66>", line 2, in minimize File "/Users/ximinlin/Documents/AI-Insects-Challenge/env/lib/python3.7/site-packages/paddle/fluid/dygraph/base.py", line 277, in __impl__ return func(*args, **kwargs) File "/Users/ximinlin/Documents/AI-Insects-Challenge/env/lib/python3.7/site-packages/paddle/fluid/optimizer.py", line 835, in minimize no_grad_set=no_grad_set) File "/Users/ximinlin/Documents/AI-Insects-Challenge/env/lib/python3.7/site-packages/paddle/fluid/optimizer.py", line 678, in backward act_no_grad_set, callbacks) File "/Users/ximinlin/Documents/AI-Insects-Challenge/env/lib/python3.7/site-packages/paddle/fluid/backward.py", line 1413, in append_backward _rename_grad_(target_grad_block, fwd_op_num, grad_to_var, {}) File "/Users/ximinlin/Documents/AI-Insects-Challenge/env/lib/python3.7/site-packages/paddle/fluid/backward.py", line 1137, in _rename_grad_ if block.desc.find_var(name.encode("ascii")): UnicodeEncodeError: 'ascii' codec can't encode character '\x90' in position 3: ordinal not in range(128)
但是我能正常使用 Res2Net101_vd_26w_4s. 下面是代码:
`def train_cls(args): data_reader = DataReader(args["batch_size"])
use_cuda = args["use_cuda"] or fluid.core.is_compiled_with_cuda()
place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace()
exe = fluid.Executor(place)
# build program
startup_prog = fluid.Program()
train_prog = fluid.Program()
with fluid.program_guard(train_prog, startup_prog):
with fluid.unique_name.guard():
train_image = fluid.data(name='image', shape=[None] + args["image_shape"],
dtype='float32')
train_label = fluid.data(name='label', shape=[None, 1], dtype='int64')
# model = SE_ResNet50_vd()
# model = SE_ResNeXt50_vd_32x4d()
# model = SENet154_vd()
# model = SE_ResNeXt50_32x4d()
model = Res2Net200_vd_26w_4s()
net_out = model.net(train_image, class_dim=args["num_classes"])
train_loss, train_pred = fluid.layers.softmax_with_cross_entropy(net_out, train_label,
return_softmax=True)
avg_train_loss = fluid.layers.mean(x=train_loss)
train_acc = fluid.layers.accuracy(input=train_pred, label=train_label, k=1)
opt = fluid.optimizer.AdamOptimizer(
learning_rate=fluid.layers.cosine_decay(args["lr"], step_each_epoch=200, epochs=300),
regularization=fluid.regularizer.L2DecayRegularizer(regularization_coeff=args["l2_decay"])
)
opt.minimize(avg_train_loss)
train_feeder = fluid.DataFeeder(place=place, feed_list=[train_image, train_label])
train_fetches = [avg_train_loss.name, train_acc.name]
`