gpt4 book ai didi

python - AssertionError : HybridBlock requires the first argument to forward be either Symbol or NDArray, 但得到

转载 作者:太空宇宙 更新时间:2023-11-04 04:06:47 25 4
gpt4 key购买 nike

我正在尝试在我的图像上运行一个预制程序,图像类型是一个 numpy 数组。当我按下回车键时,我得到了这个错误:

AssertionError: HybridBlock requires the first argument to forward be
either Symbol or NDArray, but got < class 'numpy.ndarray' >

有人知道怎么破解吗?当我在网上查看时,它说 NDArraynumpy.ndarray,所以我不确定它为什么会提示。非常感谢!

最佳答案

你必须 convert your numpy array to an mxnet NDArray :

In [11]: import numpy as np

In [12]: import mxnet as mx

In [13]: a = np.array([1, 2, 3])

In [14]: b = mx.ndarray.array(a)

In [15]: b
Out[15]:

[1. 2. 3.]
<NDArray 3 @cpu(0)>

In [16]: type(b)
Out[16]: mxnet.ndarray.ndarray.NDArray

关于python - AssertionError : HybridBlock requires the first argument to forward be either Symbol or NDArray, 但得到 <class 'numpy.ndarray' >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57173767/

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