I am preparing my data for a downstream CNN application in pytorch. I wish to use the transform methods = ToTensor() and Resize() both on the same dataset. I am not able to apply them together. from torchvision.datasets import ImageFolder from torchvision.transforms import ToTensor # In order to convert the datat to pytorch tensors from… Read More How to apply 2 different transformation on my dataset using pytorch
I’m trying to follow this tutorial to code a seq2seq translation model with pytorch: Pytorch-seq2seq Everything works perfectly fine when I train my model on cpu. The training is done, evaluation is also done and I get good results. However, the moment I switch to GPU, I get this error while evaluating on the first… Read More Why does a Torch error "Assertion `srcIndex < srcSelectDimSize` failed" only appear while training on GPU but not on CPU?
First the setup: I have the following simple model architecture: class Lin2Prop(Module): def __init__(self): super().__init__() # Property A self.al1 = Linear(159, 32) self.al2 = Linear(32, 2) # Property B #self.bl1 = Linear(159, 32) #self.bl2 = Linear(32, 1) def forward(self, x): #Property A prediction layers a_l1 = self.al1(x) a_l1 = LeakyReLU(negative_slope=0.2)(a_l1) a_l2 = self.al2(a_l1) #Property B… Read More Why I am getting this error:" RuntimeError: Trying to backward through the graph a second time
I am trying this on Kaggle: from torcheval.metrics.functional import binary_f1_score metric = binary_f1_score And i get an Error: ModuleNotFoundError Traceback (most recent call last) /tmp/ipykernel_28/3857382439.py in <module> —-> 1 from torcheval.metrics.functional import binary_f1_score 2 metric = binary_f1_score 3 model_no_CV = unet_1D().to(device) 4 optimizer = torch.optim.Adam(unet_1D.parameters(), lr=0.001) 5 epochs_num = 30 ModuleNotFoundError: No module named ‘torcheval’… Read More No module named 'torcheval'
I wanted to convert the following matrix into a PyTorch tensor: [[‘SELF’, ”, ”, ”, ”], [‘nsubj’, ‘SELF’, ”, ”, ”], [”, ‘compound’, ‘SELF’, ”, ”], [‘dobj’, ”, ”, ‘SELF’, ”], [‘pobj’, ”, ”, ”, ‘SELF’]] I wanted to have a boolean matrix where any position with a string other than empty would have a… Read More Converting matrix of strings to PyTorch tensor
I have tensor with shape: (14000, 10, 2) and another tensor with shape: (14000, 2) I want to merge the 2 tensors and get new tensor of shape: (14000, 10, 3) for example: import torch import numpy as np x = torch.rand([14000, 10, 2]) y = np.random.randint(2, size=14000) y = np.repeat(y, 10) y = torch.Tensor(y)… Read More how to merge (cat) 2 tensors ((14000, 10, 2) and (14000, 10))?
import torch from torch.autograd import Variable x = Variable(torch.FloatTensor([11.2]), requires_grad=True) y = 2 * x print(x) print(y) print(x.data) print(y.data) print(x.grad_fn) print(y.grad_fn) y.backward() # Calculates the gradients print(x.grad) print(y.grad) Error C:\Users\donhu\AppData\Local\Temp\ipykernel_9572\106071707.py:2: UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won’t be populated during autograd.backward(). If… Read More UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed
I have the following simple example code for linear regression as follows.import torch import numpy as np from torch.autograd import Variable class linearRegression(torch.nn.Module): def __init__(self, inputSize, outputSize): super(linearRegression, self).__init__() self.linear = torch.nn.Linear(inputSize, outputSize) def forward(self, x): out = self.linear(x) return out x = np.array(, dtype = np.float32).reshape(-1, 1) x = Variable(torch.from_numpy(x)) model = linearRegression(1, 1)… Read More why not called function (forward) is called in pytorch class?
I need to change the shape of tensor from [2, 48, 196] to [2, 48, 14,14]. I read there a "unflatten" in pytorch. But I couldn’t understand how to use it. Is there any example? >Solution : Here is example for your question. import torch input = torch.randn([2,48,196]) unflatten = torch.nn.Unflatten(2, (14,14)) output = unflatten(input)… Read More Unflatten in pytorch
Hi everyone I have two tensors, one tensor has as values the indicies to another tensor which contain the values I want mapped for example: a = tensor([0, 2, 5, 1, 0, 0, 4, 3, 0, 0, 0, 2,2,1]) b = tensor([1.5, 2.7, 1.8, 7.0, 3.9, 10.0]) I would like to produce a new tensor… Read More Map tensor values to another tensor