gpt4 book ai didi

python-2.7 - 在 Python 上使用 Mxnet 库运行深度学习图像分类示例时出错

转载 作者:行者123 更新时间:2023-11-30 09:10:39 25 4
gpt4 key购买 nike

我正在尝试运行 this image classification example使用 Mxnet library python 和预训练的深度学习模型 Inception-BN。执行会在这一行抛出错误:prob = model.predict(batch)[0],并显示错误消息:

MXNetError: InferShape Error in ch_concat_3c_chconcat: [14:35:56] src/operator/./concat-inl.h:152: Check failed: (dshape[j]) == (tmp[j]) Incorrect shape[2]: (1,320,15,15). (first input shape: (1,576,14,14))

我尝试再次下载 Inception-BN 模型以确保它是最新的,但没有什么区别。我确实怀疑问题可能出在网上: model = mx.model.FeedForward.load(prefix, num_round, ctx=mx.gpu(), numpy_batch_size=1) 我必须更改 gpu 代表cpu,因为我的服务器没有配备 GPU。然而,错误似乎并没有指向那个方向。

知道如何解决吗?使用 CPU 代替 GPU 除了性能较低之外还有其他问题吗?

最后是完整的错误信息:

---------------------------------------------------------------------------
MXNetError Traceback (most recent call last)
<ipython-input-7-98e51e4226e1> in <module>()
1 # Get prediction probability of 1000 classes from model
----> 2 prob = model.predict(batch)[0]
3 # Argsort, get prediction index from largest prob to lowest
4 pred = np.argsort(prob)[::-1]
5 # Get top1 label

/users/CREATE/olb/mxnet/python/mxnet/model.pyc in predict(self, X, num_batch, return_data, reset)
589 data_shapes = X.provide_data
590 data_names = [x[0] for x in data_shapes]
--> 591 self._init_predictor(data_shapes)
592 batch_size = X.batch_size
593 data_arrays = [self._pred_exec.arg_dict[name] for name in data_names]

/users/CREATE/olb/mxnet/python/mxnet/model.pyc in _init_predictor(self, input_shapes)
520 # for now only use the first device
521 pred_exec = self.symbol.simple_bind(
--> 522 self.ctx[0], grad_req='null', **dict(input_shapes))
523 pred_exec.copy_params_from(self.arg_params, self.aux_params)
524

/users/CREATE/olb/mxnet/python/mxnet/symbol.pyc in simple_bind(self, ctx, grad_req, type_dict, **kwargs)
623 if type_dict is None:
624 type_dict = {k: mx_real_t for k in self.list_arguments()}
--> 625 arg_shapes, _, aux_shapes = self.infer_shape(**kwargs)
626 arg_types, _, aux_types = self.infer_type(**type_dict)
627 if arg_shapes == None or arg_types == None:

/users/CREATE/olb/mxnet/python/mxnet/symbol.pyc in infer_shape(self, *args, **kwargs)
410 The order is in the same order as list_auxiliary()
411 """
--> 412 return self._infer_shape_impl(False, *args, **kwargs)
413
414 def infer_shape_partial(self, *args, **kwargs):

/users/CREATE/olb/mxnet/python/mxnet/symbol.pyc in _infer_shape_impl(self, partial, *args, **kwargs)
470 ctypes.byref(aux_shape_ndim),
471 ctypes.byref(aux_shape_data),
--> 472 ctypes.byref(complete)))
473 if complete.value != 0:
474 arg_shapes = [

/users/CREATE/olb/mxnet/python/mxnet/base.pyc in check_call(ret)
75 """
76 if ret != 0:
---> 77 raise MXNetError(py_str(_LIB.MXGetLastError()))
78
79 def c_str(string):

MXNetError: InferShape Error in ch_concat_3c_chconcat: [14:35:56] src/operator/./concat-inl.h:152: Check failed: (dshape[j]) == (tmp[j]) Incorrect shape[2]: (1,320,15,15). (first input shape: (1,576,14,14))

最佳答案

上述笔记本已移至notebooks repository 。我今天尝试运行它并能够成功运行该教程。问题出在旧模型中,因为接口(interface)的更改破坏了向后兼容性。看来他们已经上传了新训练的 inception-BN 模型。

如果其他人也遇到此错误,请发布此错误,只需下载新模型 here .

关于python-2.7 - 在 Python 上使用 Mxnet 库运行深度学习图像分类示例时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39832234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com