question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SafeDataset cann't wrapper different dataset

See original GitHub issue
trainset_ = my_data((140,224),transform=image_transform)
testset_ = my_data((140,224),image_set='val',transform=image_transform)

trainset = nc.SafeDataset(trainset_)
testset = nc.SafeDataset(testset_)

Before executing trainset=nc.SafeDataset(trainset_), I try to plot the first image in test by (plt.imshow(testset_[0][0].permute(1,2,0)), so I got the first image in valset which is right. After execute trainset=nc.SafeDataset(trainset_) , the (plt.imshow(testset_[0][0].permute(1,2,0)) shows me the first image in trainset which is wrong. I tried to check the image path in testset object, it’ still the the path of first image in valset. Could you give me some suggestion to solve this problem?

from PIL import Image as image
import torch
import numpy as np
import torchvision.transforms.functional as TF
import torchvision.transforms as transforms
import os
import torchvision.datasets as dset
voc_colormap = [[0, 0, 0], [128, 0, 0], [0, 128, 0], [128, 128, 0],
                [0, 0, 128], [128, 0, 128], [0, 128, 128], [128, 128, 128],
                [64, 0, 0], [192, 0, 0], [64, 128, 0], [192, 128, 0],
                [64, 0, 128], [192, 0, 128], [64, 128, 128], [192, 128, 128],
                [0, 64, 0], [128, 64, 0], [0, 192, 0], [128, 192, 0],
                [0, 64, 128]]
class my_data(torch.utils.data.Dataset):
    #if target_transform=mask_transform is
    def __init__(self,data_size,root='data',image_set='train',transform=None,target_transform=None):
        self.shape=data_size
        self.root=os.path.expanduser(root)
        self.transform=transform
        self.target_transform=target_transform
        self.image_set=image_set
        voc_dir=os.path.join(self.root,'VOCdevkit/VOC2012')
        image_dir=os.path.join(voc_dir,'JPEGImages')
        mask_dir=os.path.join(voc_dir,'SegmentationClass')
        splits_dir=os.path.join(voc_dir,'ImageSets/Segmentation')
        splits_f=os.path.join(splits_dir, self.image_set + '.txt')
        with open(os.path.join(splits_f),'r') as f:
            file_name=[x.strip() for x in f.readlines()]
        self.image=[os.path.join(image_dir,x+'.jpg') for x in file_name]
        self.mask=[os.path.join(mask_dir,x+'.png') for x in file_name]
        assert (len(self.image)==len(self.mask))

        self.class_index=np.zeros(256**3)
        for i,j in enumerate(voc_colormap):
            tmp=(j[0]*256+j[1])*256+j[2]
            self.class_index[tmp]=i
    def __getitem__(self, index):
        img=image.open(self.image[index]).convert('RGB')
        target=image.open(self.mask[index]).convert('RGB')
        i,j,h,w=transforms.RandomCrop.get_params(img,self.shape)
        # if i<0 or j<0 or h <0 or w<0:
        #     return None,None
        img=TF.crop(img,i,j,h,w)
        target=TF.crop(target,i,j,h,w)
        if  self.target_transform is not None:
            return self.transform(img),self.target_transform(target)
        target=np.array(target).transpose(2,0,1).astype(np.int32)
        target=(target[0]*256+target[1])*256+target[2]
        target=self.class_index[target]
        return self.transform(img),target

    def __len__(self):
        return len(self.image)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
eejackliucommented, Feb 6, 2019

Can you verify if the latest commit fixes the problem? 37eee52

Yes! It works! Thanks for your repo!

0reactions
msamoghcommented, Feb 5, 2019

Can you verify if the latest commit fixes the problem? 37eee520c25595ce7fe71432a34cdaea27712b1d

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't save the dataset changes to the database in C# - Visual ...
I tried to follow this tutorial HERE and couldn't get it to work either: The program compiles and executes, but the new data...
Read more >
Could not save raster dataset to (&amp;quot - Esri Community
Solved: I'm running a loop that iterates through a series of map algebra expressions and I get this error: Traceback (most recent call ......
Read more >
How to Save and Reuse Data Preparation Objects in Scikit ...
First, we need a dataset. We will use a test dataset from the scikit-learn dataset, specifically a binary classification problem with two input ......
Read more >
Datasets - Ignition User Manual 8.0
Technically, you cannot alter a dataset. Datasets are immutable, meaning they cannot change. You can, however, create new datasets. To change a ...
Read more >
Building Efficient Custom Datasets in PyTorch
We can generate multiple different datasets and play around with the ... PyTorch dataset and we did not need any other special wrappers...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found