SeitaroShinagawa/chainer-partial_convolution_image_inpainting

The error Unsupported dtype object

yuzhesu opened this issue ยท 27 comments

when I run the generate_result.py ,and set up correct, it appear The error Unsupported dtype object! How can I solve this problem?
1528703606615

Thanks for your report.
Could you check batch[i][1] in line 111 by "print(type(batch[i][1]))"?
It should be a numpy array, but it seems None in your case.
If it is None, check whether the dataset path and mask dataset path is correct or not.

I have already check batch[i][1] in line 111 by "print(type(batch[i][1])), it is None.
But I set val_dataset and mask_path correct.
Or #test_dataset I should also set it?

I have already change test_place2 in Edit common/paths.py
But when I run the generate_result.py , I still can't get the test pictures, If I want to get the test pictures, Where should I set the path?

You don't need use test_dataset.
This is a simple example to load dataset. Could you try to execute the following code?

#!/usr/bin/env python

import datasets
from common import paths

val_dataset = getattr(datasets, "place2_test")(paths.val_place2, mask_path="mask/256", resize_to=256, crop_to=256)
val_iter = chainer.iterators.SerialIterator(val_dataset, 1)
batch = val_iter.next()

print(type(batch[0][1]))
#correct return --> <class 'numpy.ndarray'>

When I execute the following code, it show <class 'NoneType'>
How can I solve this problem๏ผŸ

There are 2 possibilities, paths.val_place2 is wrong or mask_path is wrong.
Judging from your case, loading mask has failed.
Could you show the result of "ls" and "ls mask" command in the root directory of this repository?

I think paths.val_place2 is setting correct.
Where can mask_path be set๏ผŸ
Sorry, what is "ls" and "ls mask" meaning for?

Sorry, I want to see where is your mask path.
If your mask path is correct, you can do the following commands:

>>> import glob
>>> maskkeys = glob.glob("mask/256/*.bmp")
>>> print(maskkeys)
['mask/256/mask_256_00.bmp', 'mask/256/mask_256_07.bmp', 'mask/256/mask_256_09.bmp', 'mask/256/mask_256_08.bmp', 'mask/256/mask_256_06.bmp', 'mask/256/mask_256_01.bmp', 'mask/256/mask_256_02.bmp', 'mask/256/mask_256_05.bmp', 'mask/256/mask_256_04.bmp', 'mask/256/mask_256_03.bmp']

Could you try this?

1528725177543
Sorry,Is this result wrong?

Oh, I think glob has some problem with windows.
Can you load the mask from the paths? For example,

from PIL import Image
img = Image.open(maskkeys[0])

sorry , it has some problems.
1528728431226

"mask/256*.bmp" is not a list but string. I mean you should try

>>> import glob
>>> from PIL import Image
>>> maskkeys = glob.glob("mask/256/*.bmp")
>>> img = Image.open(maskkeys[0])

Does it work?

Yes, it can work.
1528731563091
So how do I generate the result correctly๏ผŸ
Thanks

I suppose cv2.imread has something wrong in your environment.
https://github.com/SeitaroShinagawa/chainer-partial_convolution_image_inpainting/blob/master/datasets/place2.py#L109

Could you try to replace this line as follows?

#mask = cv2.imread(idM, cv2.IMREAD_GRAYSCALE)
mask = np.array(Image.open(idM)).astype("f")

However, I wonder why you can excecute train.py if cv2.imread is the cause...

I have already replace this line as follows, but it still have error
1528733780664
Because I didn't perform train.py , I directly download model500000.npz to execute generate_result.py.

The error occurred in loading mask from your mask path "idM."
Surprisingly, idM has become changed to 'C:\Users\La' in your case.
Could you try "print(idM)" before the line 110 in place2.py?

I have already "print(idM)" before the line 110 in place2.py, Show the same result 'C:\Users\La'.
1528780698404
I think error is on place2.py line103 [:len(self.trainAkey)] here,
If I change line 103 to idM = self.maskkey[np.random.randint(0,len(self.maskkey))]
it will show
1528783369407
How can I correct [:len(self.trainAkey)] ?

Umm, can you do "print(self.maskkey)" before the line 110? It seems the cause you have.

1528785975752
Here!

Oh, you are right. The error should be [:len(self.trainAkey)]. Could you remove it?

I have fixed it (remove [:len(self.trainAkey)]) and it works.

ad4048b#diff-ab9bbf0e02017a0e3d0a81a64530a22eR98

Thank you for your patience!

Yes, I have already remove it, the result is
1528793944059
If I remove [:len(self.trainAkey)] results will have an impact?
Thank you for your answer patiently.

Sorry I have another question, If I want to get the Input result like this
1528794847688
How can I set?

You want to get 1 image, is it correct?
Change the input of "batch_postprocess_images"
https://github.com/SeitaroShinagawa/chainer-partial_convolution_image_inpainting/blob/master/generate_result.py#L92
Best,

No, I want to get the image like the paper's input image.

My implementation does not support it. However, you can do it by replacing the mask part value with 1.0 on each channel.

You can do like here,
https://github.com/SeitaroShinagawa/chainer-partial_convolution_image_inpainting/blob/master/generate_result.py#L88

#easiest way
output_image = F.where(M_b, I_gt, Variable(xp.ones((batchsize, 3, image_size, image_size)).astype("f"))

I understand!Thank you for your answer patiently.