torchvision

How to remove some labels of a pytorch dataset

How to remove some labels of a pytorch dataset Question: I have a torchvision.datasets object. I only want to keep some labels and delete the others. For example, if my dataset is CFAR10 like this trainset = torchvision.datasets.CIFAR10(root=’./data’, train=True, download=True) I will have 10 labels. I only want to keep the first three labels and …

Total answers: 1

FashionMNIST Dataset not transforming to Tensor

FashionMNIST Dataset not transforming to Tensor Question: Trying to calculate the mean and standard deviation of the dataset to normalise it afterwards. Current Code: train_dataset = datasets.FashionMNIST(‘data’, train=True, download = True, transform=[transforms.ToTensor()]) test_dataset = datasets.FashionMNIST(‘data’, train=False, download = True, transform=[transforms.ToTensor()]) def calc_torch_mean_std(tens): mean = torch.mean(tens, dim=1) std = torch.sqrt(torch.mean((tens – mean[:, None]) ** 2, dim=1)) …

Total answers: 1

module 'torch.onnx.symbolic_helper' has no attribute 'quantized_args'

module 'torch.onnx.symbolic_helper' has no attribute 'quantized_args' Question: while importing transforms from torchvision I am getting the following error module ‘torch.onnx.symbolic_helper’ has no attribute ‘quantized_args’ import that I performed from torchvision import transforms prior to the error it throws following warnings: OnnxExporterWarning: Symbolic function ‘aten::_shape_as_tensor’ already registered for opset 9. Replacing the existing function with new …

Total answers: 1

ModuleNotFoundError: No module named 'skimage.measure.simple_metrics'

ModuleNotFoundError: No module named 'skimage.measure.simple_metrics' Question: I am using google colab. I installed scikit-image. When I execute this code, I am getting error: ModuleNotFoundError: No module named ‘skimage.measure.simple_metrics’ import math import torch import torch.nn as nn import numpy as np import cv2 from skimage.measure.simple_metrics import compare_psnr def weights_init_kaiming(m): classname = m.__class__.__name__ if classname.find(‘Conv’) != -1: …

Total answers: 2

Dataset not found or corrupted. You can use download=True to download it

Dataset not found or corrupted. You can use download=True to download it Question: Recently I downloaded CelebA dataset from this page. I want to apply some transformations to this data set: To do it firstly let’s define transformations: from torchvision import transforms from torchvision.datasets CelebA celeba_transforms = transforms.Compose([ transforms.CenterCrop(130), transforms.Resize([64, 64]), transforms.ToTensor() ]) And now …

Total answers: 3

How do I load a local model with torch.hub.load?

How do I load a local model with torch.hub.load? Question: I need to avoid downloading the model from the web (due to restrictions on the machine installed). This works, but it downloads the model from the Internet model = torch.hub.load(‘pytorch/vision:v0.9.0’, ‘deeplabv3_resnet101’, pretrained=True) I have placed the .pth file and the hubconf.py file in the /tmp/ …

Total answers: 3

ImportError: cannot import name 'download_url_to_file'

ImportError: cannot import name 'download_url_to_file' Question: I tried to run a Python script that uses the download_url_to_file method inside the torch hub, but I got the following error: Traceback (most recent call last): File "crop-video.py", line 1, in <module> import face_alignment File "$PROGRAMS_PATH$PythonPython36libsite-packagesface_alignment-1.3.3-py3.6.eggface_alignment__init__.py", line 7, in <module> File "$PROGRAMS_PATH$PythonPython36libsite-packagesface_alignment-1.3.3-py3.6.eggface_alignmentapi.py", line 7, in <module> File "$PROGRAMS_PATH$PythonPython36libsite-packagesface_alignment-1.3.3-py3.6.eggface_alignmentutils.py", …

Total answers: 2

PyTorch : How to apply the same random transformation to multiple image?

PyTorch : How to apply the same random transformation to multiple image? Question: I am writing a simple transformation for a dataset which contains many pairs of images. As a data augmentation, I want to apply some random transformation for each pair but the images in that pair should be transformed in the same way. …

Total answers: 6

How to load a dataset starting from list of images Pytorch

How to load a dataset starting from list of images Pytorch Question: I have a service that receives images in a binary format from another service (let’s call it service B): from PIL import Image img_list = [] img_bin = get_image_from_service_B() image = Image.open(io.BytesIO(img_bin)) # Convert bytes to image using PIL When an image is …

Total answers: 1

Extracting Intermediate layer outputs of a CNN in PyTorch

Extracting Intermediate layer outputs of a CNN in PyTorch Question: I am using a Resnet18 model. ResNet( (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False) (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False) (layer1): Sequential( (0): BasicBlock( (conv1): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) …

Total answers: 3