Pytorch tensor to numpy array
I believe you also have to use .detach()
. I had to convert my Tensor to a numpy array on Colab which uses CUDA and GPU. I did it like the following:
# this is just my embedding matrix which is a Torch tensor objectembedding = learn.model.u_weightembedding_list = list(range(0, 64382))input = torch.cuda.LongTensor(embedding_list)tensor_array = embedding(input)# the output of the line below is a numpy arraytensor_array.cpu().detach().numpy()