フィーチャを計算してフィーチャに保存する機能があります。機能においてPickle TypeError inside numpy.save()
test_knn_feats = NNF.predict(X_test)
np.save('data/knn_feats_%s_test.npy' % metric , test_knn_feats)
n_jobs
が1以上であれば、次に以下のコードは実行されます。
fest_feats =[]
pool = Pool(processes = self.n_jobs)
for i in range(X.shape[0]):
test_feats.append(pool.apply_async(self.get_features_for_one(X[i:i+1])))
pool.close()
pool.join()
return np.vstack(test_feats)
しかし、エラーが発生している:
TypeError Traceback (most recent call last)
<ipython-input-96-4f707b7cd533> in <module>()
12 print(test_knn_feats)
13 # Dump the features to disk
---> 14 np.save('data/knn_feats_%s_test.npy' % metric , test_knn_feats)
/opt/conda/lib/python3.6/site-packages/numpy/lib/npyio.py in save(file, arr, allow_pickle, fix_imports)
507 arr = np.asanyarray(arr)
508 format.write_array(fid, arr, allow_pickle=allow_pickle,
--> 509 pickle_kwargs=pickle_kwargs)
510 finally:
511 if own_fid:
/opt/conda/lib/python3.6/site-packages/numpy/lib/format.py in write_array(fp, array, version, allow_pickle, pickle_kwargs)
574 if pickle_kwargs is None:
575 pickle_kwargs = {}
--> 576 pickle.dump(array, fp, protocol=2, **pickle_kwargs)
577 elif array.flags.f_contiguous and not array.flags.c_contiguous:
578 if isfileobj(fp):
機能get_features_for_one
は、以下に示すリストは、返されます。
...
knn_feats = np.hstack(return_list)
assert knn_feats.shape == (239,) or knn_feats.shape == (239, 1)
return knn_feats
*更新:
test_feats =[]
pool = Pool(processes = self.n_jobs)
for i in range(X.shape[0]):
test_feats.append(pool.apply_async(self.get_features_for_one, (X[i:i+1],)))
test_feats= [res.get() for res in test_feats]
pool.close()
pool.join()
return np.vstack(test_feats)
保存する前に 'test_knn_feats.dtype'とは何ですか?マルチスレッドとは何が関係していますか?マルチスレッド化せずに実行するとコードが動作すると言っていますか? –
私はそれを印刷するとき、それが表示されます。<0x7f1bb03ae5c0でmultiprocessing.pool.ApplyResultオブジェクト> [[<0x7f1bb02fe240でmultiprocessing.pool.ApplyResultオブジェクト> [] [<0x7f1bb02fe2b0でmultiprocessing.pool.ApplyResultオブジェクト>] ...、 [<0x7f1bb17b62b0でmultiprocessing.pool.ApplyResultオブジェクト>] [<0x7f1bb17b63c8でmultiprocessing.pool.ApplyResultオブジェクト>] [<0x7f1bb17b6518でmultiprocessing.pool.ApplyResultオブジェクト>]] –
は、それが 'ある@JohnZwinckオブジェクト 'dtype –