modAL
modAL copied to clipboard
TypeError: <class 'torch.Tensor'> datatype is not supported
Hello, I am trying to reproduce code here.
but getting the following error when execute
query_idx, query_instance = learner.query(X_pool, n_instances=100)
TypeError Traceback (most recent call last)
~/anaconda3/lib/python3.8/site-packages/modAL/models/base.py in query(self, X_pool, *query_args, **query_kwargs) 259 return query_result 260 --> 261 return query_result, retrieve_rows(X_pool, query_result) 262 263 def score(self, X: modALinput, y: modALinput, **score_kwargs) -> Any:
~/anaconda3/lib/python3.8/site-packages/modAL/utils/data.py in retrieve_rows(X, I) 99 return np.array(X)[I].tolist() 100 --> 101 raise TypeError('%s datatype is not supported' % type(X)) 102 103 TypeError: <class 'torch.Tensor'> datatype is not supported
Linux, Python 3.8.5
Env: skorch == '0.10.0' torch == '1.7.1' torchvision == '0.8.2'
Could you please give me advice how to fix the error. Maybe I am dooing something wrong or need other versions of packages.
Thanks!
Got the same wrror here Tensor datatype was not supported, but ndarray works for TF
Added X = X.detach().cpu().numpy() y = y.detach().cpu().numpy()
after
X, y = next(iter(dataloader))
, and then it worked. The cause is tensor datatype is not recognized by learner.
In the learner.teach, I modified the y=y_pool[query_idx] to the code below
learner.teach(X = X, y = torch.from_numpy(y).type(torch.LongTensor), only_new = True)

I added the below code inside the _add_training_data function
self.X_training = self.X_training.detach().cpu().numpy()
self.y_training = self.y_training.detach().cpu().numpy()

then at the end of the teach function i added this
self.X_training = torch.from_numpy(self.X_training)
self.y_training = torch.from_numpy(self.y_training)
