Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unet TypeError: function takes exactly 1 argument (3 given) #8

Open
tobimichigan opened this issue Feb 9, 2020 · 6 comments
Open

Comments

@tobimichigan
Copy link

Hi, I tried running your code but it hangs around the line below with `"unet TypeError: function takes exactly 1 argument (3 given)".
I have commented the section. Please kindly advise,

Training process

if TRAIN:
unet_model.train()
path = os.path.join('saved_models',MODEL_NAME) if SAVE_MODEL else None
unet_train_history = unet_classifier.train(EPOCHS,trainloader,mini_batch=100,save_best=path)
print(f'Training Finished after {EPOCHS} epoches')

Testing process on test data.

unet_model.eval()
unet_score = unet_classifier.test(testloader) #unet TypeError: function takes exactly 1 argument (3 given)
print(f'\n\nDice Score {unet_score}')

Dice Score 0.7446110107881675

`

@tobimichigan
Copy link
Author

tobimichigan commented Feb 9, 2020

Here are further details:

`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
7 # Testing process on test data.
8 unet_model.eval()
----> 9 unet_score = unet_classifier.test(testloader) #unet TypeError: function takes exactly 1 argument (3 given)
10 print(f'\n\nDice Score {unet_score}')
11 # Dice Score 0.7446110107881675

10 frames
Brain-Tumor-Segmentation/bts/classifier.py in test(self, testloader, threshold)
160 while len(test_data_indexes) != 0:
161 # Getting a data sample.
--> 162 data = testloader.next()
163 # Getting the data index
164 index = int(data['index'])

/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in next(self)
343
344 def next(self):
--> 345 data = self._next_data()
346 self._num_yielded += 1
347 if self._dataset_kind == _DatasetKind.Iterable and \

/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py in _next_data(self)
383 def _next_data(self):
384 index = self._next_index() # may raise StopIteration
--> 385 data = self._dataset_fetcher.fetch(index) # may raise StopIteration
386 if self._pin_memory:
387 data = _utils.pin_memory.pin_memory(data)

/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py in fetch(self, possibly_batched_index)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]

/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py in (.0)
42 def fetch(self, possibly_batched_index):
43 if self.auto_collation:
---> 44 data = [self.dataset[idx] for idx in possibly_batched_index]
45 else:
46 data = self.dataset[possibly_batched_index]

/content/Brain-Tumor-Segmentation/bts/dataset.py in getitem(self, index)
60 # Custom transformations
61 if self.transform:
---> 62 image, mask = self._random_transform(image, mask)
63
64 image = TF.to_tensor(image)

/content/Brain-Tumor-Segmentation/bts/dataset.py in _random_transform(self, image, mask)
85 if self.DEBUG:
86 print(f'\t\tRotation by: {rotation}')
---> 87 image = self.transform[choice_key](image, rotation)
88 mask = self.transform[choice_key](mask, rotation)
89 else:

/usr/local/lib/python3.6/dist-packages/torchvision/transforms/functional.py in rotate(img, angle, resample, expand, center, fill)
727 fill = tuple([fill] * 3)
728
--> 729 return img.rotate(angle, resample, expand, center, fillcolor=fill)
730
731

/usr/local/lib/python3.6/dist-packages/PIL/Image.py in rotate(self, angle, resample, expand, center, translate, fillcolor)
2003 w, h = nw, nh
2004
-> 2005 return self.transform((w, h), AFFINE, matrix, resample, fillcolor=fillcolor)
2006
2007 def save(self, fp, format=None, **params):

/usr/local/lib/python3.6/dist-packages/PIL/Image.py in transform(self, size, method, data, resample, fill, fillcolor)
2297 raise ValueError("missing method data")
2298
-> 2299 im = new(self.mode, size, fillcolor)
2300 if method == MESH:
2301 # list of quads

/usr/local/lib/python3.6/dist-packages/PIL/Image.py in new(mode, size, color)
2503 im.palette = ImagePalette.ImagePalette()
2504 color = im.palette.getcolor(color)
-> 2505 return im._new(core.fill(mode, size, color))
2506
2507

TypeError: function takes exactly 1 argument (3 given)`

@muminoff
Copy link

muminoff commented Feb 10, 2020

The same error occurs on my side too. My initial dataset was in RGB and converted it using ImageMagick to greyscale PNG file.

@tobimichigan
Copy link
Author

@muminoff , thanks for your response. I am using the same dataset suggested in the repo. Please could you elaborate further on the workaround this? I mean how to practically handle RGB issue in this case?

@muminoff
Copy link

@tobimichigan I am not maintainer of this repo. I am also issue-reporter like you. Let's wait what @sdsubhajitdas thinks about this.

@JordanMicahBennett
Copy link

@muminoff , thanks for your response. I am using the same dataset suggested in the repo. Please could you elaborate further on the workaround this? I mean how to practically handle RGB issue in this case?

It is possible that information is lost in the RGB downgrade to Grayscale.

A solution could be to retrain the model entirely, ensuring you payed attention to the shape of your new model, wrt rgb channels.

@Hamid-Naderi
Copy link

Did anyone solve this issue?
I also get the same error!
Seems there is something with Pillow library!?
I tried with version 7.1 and 8.1 but again the same error!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants