我有一个名为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
我使用的是numpy 1.8.x和numba。这里出了什么问题?
查看文档,它说:
异常NotImplementedError
此异常源自
RuntimeError
。在用户定义的基类中, 抽象方法应该引发这种异常 要求派生类重写方法。
这会如何转化为我的情况?
关于我如何调用火车功能的更多细节:
#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)
答案 0 :(得分:0)
@Korem是对的!
我实际上是从这样的文件加载img_hogs
变量:
img_hogs = np.array(pickle.load(file("C:\\PATH_TO_FILE")), dtype=object)
我一直在忽视这一点。 当我最终删除了dtype = object位时,它工作了!