tensor

Problem loading parallel datasets even after using SubsetRandomSampler

Problem loading parallel datasets even after using SubsetRandomSampler Question: I have two parallel datasets dataset1 and dataset2 and following is my code to load them in parallel using SubsetRandomSampler where I provide train_indices for dataloading. P.S. Even after setting num_workers=0 and seeding np as well as torch, the samples do not get loaded in parallel. …

Total answers: 2

Appending zero rows to a 2D Tensor in PyTorch

Appending zero rows to a 2D Tensor in PyTorch Question: Suppose I have a tensor 2D tensor x of shape (n,m). How can I extend the first dimension of the tensor by appending zero rows in x by specifying the indices of where the zero rows will be located in the resulting tensor? For a …

Total answers: 2

Append or combine column wise torch tensors of different shapes

Append or combine column wise torch tensors of different shapes Question: Tensors A and B below share the row size. The 6 and 3 refers to the columns of the 2 data frame, but the B tensor has at each cell a vector of size 256. A= torch.Size([17809, 6]) B= torch.Size([17809, 3, 256]) How do …

Total answers: 1

How to turn a cifar10 dataset into a tensor

How to turn a cifar10 dataset into a tensor Question: I am trying to turn the cifar10 dataset into a tensor with trainset = datasets.CIFAR10(root=’./data’, train=True, download=True, transform=transforms.ToTensor()) but it continually returns false when I run it torch.is_tensor(trainset) function which means it’s not a tensor and it also doesn’t work for functions that require tensors …

Total answers: 1

Tensor repeat for image patches

Tensor repeat for image patches Question: I have a batch of 20 flattened tensors representing 256X256 images. >>> imgs.shape (20, 65536) Each image was split into 32×32 patches (a total of 64 patches per image). I have calculated a score for each patch and got a vector with the shape of (20,64) I would like …

Total answers: 1

How do I increment certain values in Tensorflow tensor?

How do I increment certain values in Tensorflow tensor? Question: I want to increment certain values of an tensor in Tensorflow. The code I am attempting to use is: outs[h, i:i+self.cnv, j:j+self.cnv] += (self.b*counts)/sums I am not sure how to do this, and the shapes of the Tensors do match, and I am using tf …

Total answers: 1

From a 2D tensor, return a 1D tensor by selecting 1 column per row

From a 2D tensor, return a 1D tensor by selecting 1 column per row Question: I have a 2D tensor and a 1D tensor: import torch torch.manual_seed(0) out = torch.randn((16,2)) target = torch.tensor([0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0]) For each row of out, I want …

Total answers: 1

How to read all numpy files (.npy) from directory at once without For loop?

How to read all numpy files (.npy) from directory at once without For loop? Question: I have 1970 npy files in (vid_frames) directory each npy file contains 20 frame of MSVD dataset. I need to load all these npy at once to be as tensor dataset. When I use np_read = np.load(all_npy_path) , I get …

Total answers: 2

How to extract Integer from Pytorch Tensor

How to extract Integer from Pytorch Tensor Question: This is a part of code… VSCODE declares variable > xyxy as ‘list’ for *xyxy, conf, cls in reversed(det): if save_txt: # Write to file xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format …

Total answers: 1