It would be nice to see your train_generator code for clarity, but it does not seem to be a torch DataLoader. In this case, you should probably convert your arrays to tensors manually. There are several ways to do so:
torch.from_numpy(numpy_array)- for numpy arrays;torch.as_tensor(list)- for common lists and tuples;torch.tensor(array)should also work but the above ways will avoid copying the data when possible.
Top answer 1 of 12
1
adv_ex is already a numpy array, so you can’t call .numpy() again on it (which is a tensor method).
Store adv_ex as a tensor or avoid calling numpy on it:
adv_ex = perturbed_data.squeeze().detach().cpu()
adv_examples.append( (init_pred.item(), final_pred.item(), adv_ex) )
2 of 12
0
Thanks!. My bad, I haven’t noticed that it is already called.
cnt = 0
plt.figure(figsize=(8,10))
for i in range(len(epsilons)):
for j in range(len(examples[i])):
cnt += 1
plt.subplot(len(epsilons),len(examples[0]),cnt)
plt.xticks([], [])
plt.yticks([], [])
…
PyTorch Forums
discuss.pytorch.org › t › attributeerror-numpy-ndarray-object-has-no-attribute-log › 117472
AttributeError: 'numpy.ndarray' object has no attribute 'log' - PyTorch Forums
April 8, 2021 - It seems you are trying to pass a numpy array to F.nll_loss, while a PyTorch tensor is expected. I’m not sure how y_pred is calculated, but note that using numpy array would detach them from the computation graph, so you should stick to PyTorch tensors and operations, if possible · Remove ...
PyTorch Forums
discuss.pytorch.org › t › attributeerror-numpy-ndarray-object-has-no-attribute-dim › 16026
AttributeError: 'numpy.ndarray' object has no attribute 'dim' - PyTorch Forums
April 5, 2018 - Hello Team, i am new to the forum and to Pytorch, i want to predict 3 real values Y1, Y2 & Y3 from input values X1, X2…X10 using the below model, but i get the error in title: File “/home/abdelmoula/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py”, line 833, in linear if input.dim() == 2 and bias is not None: AttributeError: ‘numpy.ndarray’ object has no attribute ‘dim’ Can you please on what is wrong ? thank you ######################## MODEL: import pandas as pd import to...
GitHub
github.com › pytorch › pytorch › issues › 41657
AttributeError: 'numpy.ndarray' object has no attribute 'dim' · Issue #41657 · pytorch/pytorch
July 19, 2020 - return torch.argmax(self.dqn(state)) File "/home/veds12/anaconda3/envs/AI/lib/python3.6/site-packages/torch/nn/modules/module.py", line 550, in __call__ result = self.forward(*input, **kwargs) File "/home/veds12/anaconda3/envs/AI/lib/python3.6/site-packages/torch/nn/modules/container.py", line 100, in forward input = module(input) File "/home/veds12/anaconda3/envs/AI/lib/python3.6/site-packages/torch/nn/modules/module.py", line 550, in __call__ result = self.forward(*input, **kwargs) File "/home/veds12/anaconda3/envs/AI/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 87, in forward return F.linear(input, self.weight, self.bias) File "/home/veds12/anaconda3/envs/AI/lib/python3.6/site-packages/torch/nn/functional.py", line 1608, in linear if input.dim() == 2 and bias is not None: AttributeError: 'numpy.ndarray' object has no attribute 'dim'
Author veds12
GitHub
github.com › pytorch › vision › issues › 7414
Load MNIST from torchvision AttributeError: 'numpy.ndarray' object has no attribute 'numpy' · Issue #7414 · pytorch/vision
March 11, 2023 - 🐛 Describe the bug I can not load MNIST from torchvision. AttributeError: 'numpy.ndarray' object has no attribute 'numpy' def build_transforms_mnist(normalize=False): if normalize: ...
Author rikonaka
PyTorch Forums
discuss.pytorch.org › t › how-to-fix-attributeerror-numpy-ndarray-object-has-no-attribute-cpu › 158960
How to fix: "AttributeError: 'numpy.ndarray' object has no attribute 'cpu'" - PyTorch Forums
August 11, 2022 - Hi All I have data from a dataloader which I get a data and corresponding label from it. I am trying to normalize the labels within a certain range using T.tonumpy_denormalize , however I get this error AttributeError: 'numpy.ndarray' object has no attribute 'cpu'.
Top answer 1 of 2
2
.numel() is defined for PyTorch tensors, not numpy arrays. Based on your error message it seems that you are using numpy arrays inside your Dataset, which then fails in:
numel = sum([x.numel() for x in batch])
Assuming the __getitem__ returns these numpy arrays (I don’t have a clue which types the…
2 of 2
1
Thanks @ptrblck, I realized the question was quite basic and i solved it!
You are awesome!
I wish u a fantastic day!
GitHub
github.com › open-edge-platform › anomalib › issues › 2452
[Bug]: AttributeError: 'numpy.ndarray' object has no attribute 'to' · Issue #2452 · open-edge-platform/anomalib
December 5, 2024 - PyTorch version: [e.g. 1.9.0] CUDA/cuDNN version: [e.g. 11.1] GPU models and configuration: [e.g. 2x GeForce RTX 3090] Any other relevant information: [e.g. I'm using a custom dataset] ... def pre_process(self, image: np.ndarray) -> torch.Tensor: """Pre process the input image.
Author Septembit
Top answer 1 of 2
1
Hi @arturn
Many thanks for your reply.
I fixed the error. Actually, it was my fault to send observation as a dictionary to the conpute_action method. But, the right datatype is a nparray.
For those who got into the same problem, here is the solution:
policy_id = self.config['multiagent']['policy…
2 of 2
0
Hi @deepgravity
This should not happen. RLlib converts the complete content of the input_dict to torch tensors before computing actions.
Can you breakpoint into this function? … or maybe to this line and see what happens there?
Cheers!
Stack Overflow
stackoverflow.com › questions › 74551169 › getting-attributeerror-numpy-ndarray-object-has-no-attribute-dim-when-conve
python - getting AttributeError: 'numpy.ndarray' object has no attribute 'dim' when converting tensorflow code to pytorch - Stack Overflow
Python Neural Network: 'numpy.ndarray' object has no attribute 'dim' ... torch.stft is a PyTorch function and expects a Tensor as the input. You must convert your NumPy array into a tensor and then pass that as the input.
PyTorch Forums
discuss.pytorch.org › t › attributeerror-numpy-ndarray-object-has-no-attribute-mode › 127130
AttributeError: 'numpy.ndarray' object has no attribute 'mode' - PyTorch Forums
July 19, 2021 - I guess your code expects img_group to be a list (or another container) containing PIL.Images, which provide the mode attribute · I don’t think you would necessarily need to transform the inputs first to PIL.Images, as the method seems to return numpy arrays.
GitHub
github.com › mrdbourke › pytorch-deep-learning › discussions › 568
i also write code properly and some times i am copying form this code but always shows the AttributeError: 'numpy.ndarray' object has no attribute 'to' · mrdbourke/pytorch-deep-learning · Discussion #568
July 25, 2023 - i also write code properly and some times i am copying form this code but always shows the AttributeError: 'numpy.ndarray' object has no attribute 'to' #568
Author mrdbourke
PyTorch Forums
discuss.pytorch.org › t › attributeerror-numpy-ndarray-object-has-no-attribute-cpu › 79512
AttributeError: 'numpy.ndarray' object has no attribute 'cpu' - PyTorch Forums
May 3, 2020 - Hi, I am having a problem in plotting the accuracy of trained model, I adopted the following code for plotting the accuracy from tutorial Finetuning Torchvision Models — PyTorch Tutorials 2.2.0+cu121 documentation. Here is the code, ohist = [] shist = [] ohist = [h.cpu().numpy() for h in epoch_accuracy_o] shist = [h.cpu().numpy() for h in epoch_accuracy_s] print(ohist) print(shist) plt.title("Validation Accuracy vs.
PyTorch Forums
discuss.pytorch.org › vision
Creating tensor TypeError: can't convert np.ndarray of type numpy.object_ - vision - PyTorch Forums
July 4, 2021 - X = final_df.values y = df['Target'].values from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.4, random_state=42) train_inputs = torch.tensor(X_train,dtype=torch.float).tag("#iot", "#network","#data","#train") train_labels ...
PyTorch Forums
discuss.pytorch.org › reinforcement-learning
AttributeError: 'numpy.ndarray' object has no attribute 'dim' from torch/nn/functional.py - reinforcement-learning - PyTorch Forums
January 10, 2020 - I’m working on a DDPG implementation and getting AttributeError: 'numpy.ndarray' object has no attribute 'dim' from my Actor class. Based on answer here https://discuss.pytorch.org/t/attributeerror-numpy-ndarray-object-has-no-attribute-dim/16026/2, I tried using Variable(), however, the args are Tensors already and I get the TypeError: expected np.ndarray (got Tensor) error.