TypeError: object() takes no parameters

username: PytorchLearning
cooked: <p>Hi all,</p>
<p>I have two folders, the first folder contain Original Images and the second folder contain the same Images with noise and I have no label. When I added path and loading images from paths in the code I get this error:</p>
<p>1 train_dataset = Dataset(path_input_1 = path_input_1<br>
----&gt; 2 ,path_input_2 = path_input_2)</p>
<p>TypeError: object() takes no parameters</p>
<p>Can someone please tell me where the errors are and how to fix it. Here is the code:</p>
<pre><code>class Dataset(data.Dataset):
	def __int__(self, path_input_1, path_input_2):
		"""
		Initialize data set as a list of paths corresponding to each item of data set

        Args:
		    path_inputs: a list of paths for each data point in data set
		"""

        self.filenames_OI = []
		self.filenames_NI = []

	# list of paths to original images and noise images
		self.path_input_1 = path_input_1     # list of paths to original images        
		self.path_input_2 = path_input_2     # list of paths to images with noise

		filenames_OI = glob.glob(osp.join(path_input_1, '*.jpg'))
		filenames_NI = glob.glob(osp.join(path_input_2, '*.jpg'))

		for fn_OI, fn_NI in filenames_OI, filenames_NI:
    			self.filenames_OI.append(fn_OI)
    			self.filenames_NI.append(fn_NI)

	def __len__(self):
		"""
		Return the length of data set using list of paths
    	:return: number of samples in data set
		"""
		return len(self.path_input_1) 

	def __getitem__(self, index):

    	# Code to load data using Image.open
		x = Image.open(self.filenames_OI[index])
		y = Image.open(self.filenames_NI[index])

    	return X, y


train_dataset = Dataset(path_input_1 = path_input_1
                       ,path_input_2 = path_input_2)</code></pre>

username: Nikronic
cooked: <p>Hi,</p>
<p>I ran your code and it works fine.<br>
Although there was a lot of problem with indentation. You may wannt to reformat your code using a framework or use a proper IDE/editor.</p>
<pre><code class="lang-auto">class Dataset(data.Dataset):
    def __init__(self, path_input_1, path_input_2):
        self.filenames_OI = []
        self.filenames_NI = []
        self.path_input_1 = path_input_1
        self.path_input_2 = path_input_2

        filenames_OI = glob.glob(osp.join(path_input_1, '*.jpg'))
        filenames_NI = glob.glob(osp.join(path_input_2, '*.jpg'))

        for fn_OI, fn_NI in filenames_OI, filenames_NI:
            self.filenames_OI.append(fn_OI)
            self.filenames_NI.append(fn_NI)

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

    def __getitem__(self, index):
        x = Image.open(self.filenames_OI[index])
        y = Image.open(self.filenames_NI[index])
        return X, y


train_dataset = Dataset(path_input_1 = 'path' ,path_input_2 = 'another/path')
</code></pre>
<p>Bests</p>

username: PytorchLearning
cooked: <p>Hi <a class="mention" href="/u/nikronic">@Nikronic</a>,</p>
<p>First, thanks a lot for your precious help.</p>
<p>You said I may want to reformat my code using a framework or use a proper IDE/editor.  I am using Jupyter notebook (anaconda software) and the Preview (Nightly) pytorch version.</p>

username: Nikronic
cooked: <p>You are welcome,<br>
Ok, nightly builds may have some bugs or differences which I am not aware of. I ran your code and there was no problem using the stable build. Can you try to run your code using exact same pytorch version on google colab and share it?<br>
Can you also print the full stack trace?</p>

username: PytorchLearning
cooked: <p>Hi <a class="mention" href="/u/nikronic">@Nikronic</a></p>
<p>First thanks for your precious help.</p>
<p>Here are all the steps but I get another error. Do you know why?</p>
<p>I am using the Preview (Nightly) pytorch version because I am interesting by using<br>
from torch.cuda import amp which exist only on the Nightly version.</p>
<p>my following folders are:</p>
<p>C:/DataSets/SimplifyData/imagesForTrain/OriginalImages/<br>
and<br>
C:/DataSets/SimplifyData/imagesForTrain/imagesForTrain/NoiseImages/</p>
<p>I have put in each folder (OriginalImages and NoiseImages) three .jpg images only for test:</p>
<p>Here is the complete code:</p>
<pre><code>import os
import glob

import torch
import torch.cuda as cuda
import torch.nn as nn
from torch.nn import functional as F
from torch.utils import data

import matplotlib.pyplot as plt
import matplotlib.image as matpltimg

import torchvision
from torchvision import datasets
from torchvision import transforms

import numpy as np

from torch.cuda import amp

datadir  = '/DataSets/SimplifyData'

traindir_OI = datadir + '/imagesForTrain/OriginalImages/'
traindir_NI = datadir + '/imagesForTrain/NoiseImages/'

class Dataset(data.Dataset):
    def __init__(self, path_input_1, path_input_2):
    	self.filenames_OI = []
    	self.filenames_NI = []
    	self.path_input_1 = path_input_1
    	self.path_input_2 = path_input_2

        filenames_OI = glob.glob(osp.join(path_input_1, '*.jpg'))
    	filenames_NI = glob.glob(osp.join(path_input_2, '*.jpg'))

        for fn_OI, fn_NI in filenames_OI, filenames_NI:
    	        self.filenames_OI.append(fn_OI)
        		self.filenames_NI.append(fn_NI)

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

    def __getitem__(self, index):
    	x = Image.open(self.filenames_OI[index])
    	y = Image.open(self.filenames_NI[index])
    	return X, y

import os
import glob
import os.path as osp
from PIL import Image

path_labels = traindir_OI
path_inputs = traindir_NI

train_dataset = Dataset(path_input_1 = path_labels
    	               ,path_input_2 = path_inputs)
</code></pre>
<p>Now I get this error:</p>
<hr>
<p>ValueError                                Traceback (most recent call last)<br>
 in <br>
1 train_dataset = Dataset(path_input_1 = path_labels<br>
----&gt; 2                        ,path_input_2 = path_inputs)</p>
<p> in <strong>init</strong>(self, path_input_1, path_input_2)<br>
9         filenames_NI = glob.glob(osp.join(path_input_2, ‘*.jpg’))<br>
10<br>
—&gt; 11         for fn_OI, fn_NI in filenames_OI, filenames_NI:<br>
12             self.filenames_OI.append(fn_OI)<br>
13             self.filenames_NI.append(fn_NI)</p>
<p>ValueError: not enough values to unpack (expected 2, got 0)</p>

username: Nikronic
cooked: <aside class="quote no-group" data-username="PytorchLearning" data-post="5" data-topic="88277">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/p/d2c977/48.png" class="avatar"> PytorchLearning:</div>
<blockquote>
<p>ValueError: not enough values to unpack (expected 2, got 0)</p>
</blockquote>
</aside>
<p>This means your path is wrong or there is no image in the used path. Literally, <code>filenames_NI</code> and <code>filenames_OI</code> are empty. Make sure you are using correct path, for instance, put a <code>print(len(filenames_NI))</code> before the error loop.</p>

username: PytorchLearning
cooked: <p><a class="mention" href="/u/nikronic">@Nikronic</a> thanks I will try</p>

username: PytorchLearning
cooked: <p>Hi <a class="mention" href="/u/nikronic">@Nikronic</a></p>
<p>I have checked if my folder are empty as follow;</p>
<pre><code class="lang-auto">import os
import glob

import torch
import torch.cuda as cuda
import torch.nn as nn
from torch.nn import functional as F
from torch.utils import data

import matplotlib.pyplot as plt
import matplotlib.image as matpltimg

import torchvision
from torchvision import datasets
from torchvision import transforms

import numpy as np

from torch.cuda import amp

datadir  = '/DataSets/SimplifyData'

traindir_OI = datadir + '/imagesForTrain/OriginalImages/'
traindir_NI = datadir + '/imagesForTrain/NoiseImages/'

list1 = os.listdir(traindir_OI) 
number_files1 = len(list1)
print(number_files1)

list2 = os.listdir(traindir_NI) 
number_files2 = len(list2)
print(number_files2)
</code></pre>
<p>I get as result :<br>
6<br>
6</p>
<p>which is correct because in each folder I have put now 6 images.</p>
<p>I have also tested the folders as follow:</p>
<pre><code class="lang-auto">class Dataset(data.Dataset):
    def __init__(self, path_input_1, path_input_2):
        self.filenames_OI = []
        self.filenames_NI = []
        self.path_input_1 = path_input_1
        self.path_input_2 = path_input_2

        filenames_OI = glob.glob(osp.join(path_input_1, '*.jpg'))
        filenames_NI = glob.glob(osp.join(path_input_2, '*.jpg'))
        print(len(filenames_OI)) 
        print(len(filenames_NI))
        
        for fn_OI, fn_NI in filenames_OI, filenames_NI:
            self.filenames_OI.append(fn_OI)
            self.filenames_NI.append(fn_NI)

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

    def __getitem__(self, index):
        x = Image.open(self.filenames_OI[index])
        y = Image.open(self.filenames_NI[index])
        return X, y
</code></pre>
<p>I get also:<br>
6<br>
6</p>
<p>So I don’t known why I have the error. ValueError: not enough values to unpack (expected 2, got 0)</p>
<p>Perhaps I have done something wrong in the code, but I don’t known what.</p>

username: Nikronic
cooked: <aside class="quote no-group" data-username="PytorchLearning" data-post="8" data-topic="88277">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/p/d2c977/48.png" class="avatar"> PytorchLearning:</div>
<blockquote>
<p><code>for fn_OI, fn_NI in filenames_OI, filenames_NI:</code></p>
</blockquote>
</aside>
<p>Ow I am really sorry, I forgot many things. In python when you want to loop over two things, you need to use <code>zip</code> like this:</p>
<pre><code class="lang-auto">for fn_OI, fn_NI in zip(filenames_OI, filenames_NI):
</code></pre>
<p>Let me know if it works.</p>

username: PytorchLearning
cooked: <p>Hi <a class="mention" href="/u/nikronic">@Nikronic</a></p>
<p>Thank you very much, everything works very well.</p>