我按照 example/warpctc/ lstm_ocr.py来训练模型。现在我保存了一个检查点 mymodel-0100.params 和 mymodel-symbol.json。
那么,我怎样才能使用这个检查点进行预测,只使用一张图像呢?
我已经厌倦了使用 Predictor 界面,代码如下:
# Load the pre-trained model
symbol_file = "mymodel-symbol.json"
param_file = "mymodel-0100.params"
predictor = Predictor(open(symbol_file).read(),
open(param_file).read(),
{'data':(80, 30)})
但是数据形状总是会引发错误,我不知道如何设置这个值。有人帮我谢谢。
不过,我也尝试了另一种方法:在 mxnet/example/warpctc/ lstm_ocr.py末尾添加一行代码:
model = mx.model.FeedForward(ctx=contexts,
symbol=symbol,
num_epoch=num_epoch,
learning_rate=learning_rate,
momentum=momentum,
wd=0.00001,
initializer=mx.init.Xavier(factor_type="in", magnitude=2.34))
model.fit(X=data_train, eval_data=data_val,
eval_metric = mx.metric.np(Accuracy),
batch_end_callback=mx.callback.Speedometer(BATCH_SIZE, 50),)
model.save("ocr")
# add new line for predict
model.predict(data_val)
但它总是错误输出:
Traceback (most recent call last):
File "lstm_ctc_ocr.py", line 211, in <module>
training_all()
File "lstm_ctc_ocr.py", line 188, in training_all
model.predict(data_val)
File "/home/bobliu/Work/code/DL/mxnet/python/mxnet/model.py", line 618, in predict
self._init_predictor(data_shapes, type_dict)
File "/home/bobliu/Work/code/DL/mxnet/python/mxnet/model.py", line 541, in _init_predictor
self.ctx[0], grad_req='null', type_dict=type_dict, **dict(input_shapes))
File "/home/bobliu/Work/code/DL/mxnet/python/mxnet/symbol.py", line 685, in simple_bind
arg_types, _, aux_types = self.infer_type(**type_dict)
File "/home/bobliu/Work/code/DL/mxnet/python/mxnet/symbol.py", line 417, in infer_type
ctypes.byref(complete)))
File "/home/bobliu/Work/code/DL/mxnet/python/mxnet/base.py", line 77, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: InferType Error in reshape0: [21:39:03] src/operator/./reshape-inl.h:345: Check failed: (dtype) != (-1) First input must have specified type