问题描述
prefix = 'model/model_algo_1'
epoch = 0
sym,arg_params,aux_params = mx.model.load_checkpoint(prefix,0)
vgg_16 = mx.mod.Module(symbol=sym,data_names=('data',),label_names=('label',)
)
该模型已按上述方式加载到我的本地计算机中。 epoch = 0
用作我的.params文件名,前缀后有0000。该模型是在 AWS Sagemaker 中使用内置的对象检测算法训练后获得的。我没有对模型文件进行任何其他操作。
内置型号:VGG16
我在本地计算机上使用的MXNet版本:1.6.0
vgg_16.bind(for_training=False,data_shapes=[('data',(1,3,300,300))],label_shapes=[('label',1,350))]
)
vgg_16.set_params(arg_params,aux_params,allow_missing = True,allow_extra = True)
我如上所述绑定数据。
def preparendarray(filename):
img = cv2.imread(filename)
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
img = cv2.resize(img,(300,))
img = np.swapaxes(img,2)
img = np.swapaxes(img,2)
img = img[np.newaxis,:]
array = mx.nd.array(img)
print(array.shape)
return array
以上方法是我的图像转换方法。这样就得到了(1,300)形状的ndarray。
test_im = preparendarray(image)
Batch=namedtuple('Batch',['data'])
vgg_16.forward(Batch(test_im))
Traceback (most recent call last):
File "D:\RA-Work\Maritime\Code\modelRun\modeltesting.py",line 106,in <module>
vgg_16.forward(Batch(test_im))
File "G:\Anaconda-spyder\lib\site-packages\mxnet\module\module.py",line 625,in forward
self.reshape(new_dshape,new_lshape)
File "G:\Anaconda-spyder\lib\site-packages\mxnet\module\module.py",line 472,in reshape
self._exec_group.reshape(self._data_shapes,self._label_shapes)
File "G:\Anaconda-spyder\lib\site-packages\mxnet\module\executor_group.py",line 397,in reshape
self.bind_exec(data_shapes,label_shapes,reshape=True)
File "G:\Anaconda-spyder\lib\site-packages\mxnet\module\executor_group.py",line 373,in bind_exec
allow_up_sizing=True,**dict(data_shapes_i + label_shapes_i))
File "G:\Anaconda-spyder\lib\site-packages\mxnet\executor.py",line 458,in reshape
ctypes.byref(handle)))
File "G:\Anaconda-spyder\lib\site-packages\mxnet\base.py",line 255,in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
MXNetError: Error in operator conv1_1: [10:27:50] C:\Jenkins\workspace\mxnet-tag\mxnet\src\operator\nn\convolution.cc:152: Check Failed: dshp.ndim() == 4U (3 vs. 4) : Input data should be 4D in batch-num_filter-y-x
所以我想要获得检测输出。
我还尝试使用Module API中的预测函数。
result = vgg_16.predict(test_im)
这给出了以下输出。
[[[0.99753714 0.9983798 0.99425286 ... 0.78984463 0.74393696 0.96449393]
[0.00246283 0.0016202 0.0057471 ... 0.21015535 0.25606307 0.03550606]]]
<ndarray 1x2x8732 @cpu(0)>
但我在解释此输出时发现困难。因为此模型经过了1类培训。如何从此数据中提取包围盒的信息?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)