gpt4 book ai didi

python - 使用 numba 类方法时出现 NotImplementedError(dtype)

转载 作者:太空宇宙 更新时间:2023-11-03 18:12:14 30 4
gpt4 key购买 nike

我正在使用 numpy 1.8.x 和 numba。我有一个名为 train 的函数,它具有以下定义:

@autojit 
def train_function( X, y, H):

它返回一个 3D numpy 数组。

然后我有一个类,它调用这个函数,如下所示:

class GentleBoostC(object):
# different methods including init
# and now the train function
def train(self, X, y, H):
self.g_per_round = train_function(X,y,H)

然后我实例化该类并使用它来训练对象。

# initiate the variables X_train, y_train and boosting_rounds
gentlebooster = gbc.GentleBoostC() # gbc has already been imported
gentlebooster.train(X_train,y_train,boosting_rounds)

但是我收到了这个错误:

    gentlebooster.train(X_train,y_train,boosting_rounds)
File "C:\Users\app\Documents\Python Scripts\gentleboost_c_class_jit_v7_nolimit.py", line 299, in train
self.g_per_round = train_function(self,X, y, H)
File "C:\Anaconda\lib\site-packages\numba\dispatcher.py", line 152, in typeof_pyval
dtype = numpy_support.from_dtype(val.dtype)
File "C:\Anaconda\lib\site-packages\numba\numpy_support.py", line 61, in from_dtype
raise NotImplementedError(dtype)
NotImplementedError: object

这里出了什么问题?

编辑

查看文档,它说:

exception NotImplementedError

This exception is derived from RuntimeError. In user defined base classes, abstract methods should raise this exception when they require derived classes to override the method.

这将如何转化为我的案例?

编辑

有关如何调用训练函数的更多详细信息:

#img_hogs and sample_labels have already been populated above, both are numpy arrays
X_train = np.array(img_hogs)
y_train = np.array(sample_labels)
boosting_rounds = 7

gentlebooster = gbc.GentleBoostC()
gentlebooster.train(X_train,y_train,boosting_rounds)

最佳答案

我的数组X_train是一个numpy对象数组,并且numba does not support that .

@Korem 是对的!我实际上是从这样的文件加载 img_hogs 变量:

img_hogs = np.array(pickle.load(file("C:\\PATH_TO_FILE")), dtype=object)

我只是一直忽视这一点。当我最终删除 dtype=object 位时,它起作用了!

关于python - 使用 numba 类方法时出现 NotImplementedError(dtype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25704645/

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