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

Issues importing my own dataset #366

Closed
ben-coo-per opened this issue Sep 27, 2019 · 10 comments
Closed

Issues importing my own dataset #366

ben-coo-per opened this issue Sep 27, 2019 · 10 comments

Comments

@ben-coo-per
Copy link

I have been troubleshooting this for a few days now and I think it's about time to ask.
I have tried importing a couple of datasets that I reshaped with PIL to 96x96(RGB).

When I use one of the datasets and specify the input_height and output_height flags i get this error:

....DCGAN-tensorflow-master/utils.py", line 104, in transform
im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
NameError: name 'j' is not defined

When I specify the --crop flag I get this:

....DCGAN-tensorflow-master/utils.py", line 94, in center_crop
im = Image.fromarray(x[j:j+crop_h, i:i+crop_w])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/PIL/Image.py", line 2517, in fromarray
raise TypeError("Cannot handle this data type")
TypeError: Cannot handle this data type

With all this being said, I think it is an issue with my images and the crop function. I have used the mnist dataset and it works fine.

For reference on what my images are, I have attached two.
If you have any advice on what I can change to fix this issue I would really appreciate it.

000
001

@wflaschka
Copy link

I just ran into the same issue and looked into the code.

It looks like the errors are caused by using the --crop argument on the commandline, which activates some wonky resizing / transforming / cropping logic in utils.py. However, if you do not use --crop, then you still get an error due to undefined values for i, j, etc in line 104.

Since all my images are already sized, cropped, and share a consistent colorspace, I simply skipped the wonky code by commenting lines 43-44 in utils.py:

  return transform(image, input_height, input_width,
                   resize_height, resize_width, crop)

And substituting with:

return image

Everything appears to be working smoothly now and my model is fitting. Give it a shot?

@ben-coo-per
Copy link
Author

ben-coo-per commented Oct 11, 2019

It looks like that worked. Thank you for your help!

@MyLovePoppet
Copy link

changed the code became a new error...

[] Reading checkpoints... ./out\20191014.164103 - data - faces - x108.z100.uniform_signed.y64.b64\checkpoint
[
] Failed to find a checkpoint
[!] Load failed...
Traceback (most recent call last):
File "main.py", line 147, in
tf.app.run()
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 299, in run
_run_main(main, args)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 250, in _run_main
sys.exit(main(argv))
File "main.py", line 120, in main
dcgan.train(FLAGS)
File "H:\2019Summer\代码\DCGAN\DCGAN-tensorflow-master\model.py", line 279, in train
feed_dict={ self.inputs: batch_images, self.z: batch_z })
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
run_metadata_ptr)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1149, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (64, 96, 96, 3) for Tensor 'real_images:0', which has shape '(64, 64, 64, 3)'

@taotaoyuhust
Copy link

是utils.py 文件中的imread函数导致的问题,最后return的时候转换成了float,crop的时候Image.fromarray这句就会报错,
可将imread的返回改为return img_rgb
或在后面转成uint8

@taotaoyuhust
Copy link

另外,transform函数中有严重的bug
crop为true的时候,return还是返回的im

@Jumpleoleoleo
Copy link

changed the code became a new error...

[] Reading checkpoints... ./out\20191014.164103 - data - faces - x108.z100.uniform_signed.y64.b64\checkpoint [] Failed to find a checkpoint
[!] Load failed...
Traceback (most recent call last):
File "main.py", line 147, in
tf.app.run()
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 299, in run
_run_main(main, args)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 250, in _run_main
sys.exit(main(argv))
File "main.py", line 120, in main
dcgan.train(FLAGS)
File "H:\2019Summer\代码\DCGAN\DCGAN-tensorflow-master\model.py", line 279, in train
feed_dict={ self.inputs: batch_images, self.z: batch_z })
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
run_metadata_ptr)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1149, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (64, 96, 96, 3) for Tensor 'real_images:0', which has shape '(64, 64, 64, 3)'

Same problem!
Have you solved this problem?

@MyLovePoppet
Copy link

changed the code became a new error...
[] Reading checkpoints... ./out\20191014.164103 - data - faces - x108.z100.uniform_signed.y64.b64\checkpoint [] Failed to find a checkpoint
[!] Load failed...
Traceback (most recent call last):
File "main.py", line 147, in
tf.app.run()
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 299, in run
_run_main(main, args)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 250, in _run_main
sys.exit(main(argv))
File "main.py", line 120, in main
dcgan.train(FLAGS)
File "H:\2019Summer\代码\DCGAN\DCGAN-tensorflow-master\model.py", line 279, in train
feed_dict={ self.inputs: batch_images, self.z: batch_z })
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
run_metadata_ptr)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1149, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (64, 96, 96, 3) for Tensor 'real_images:0', which has shape '(64, 64, 64, 3)'

Same problem!
Have you solved this problem?

Yes, from zhihu link "https://zhuanlan.zhihu.com/p/24767059" the @igoindown ’s comment,

His solution is working for me:

我运行过程中一共遇到了4个问题:

1:TypeError: Cannot handle this data type

跟着代码一步步crtl+b进utils.py把94行改为:

im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

2:再run; 95行会报错 data type not understood

把95行改为:return np.array(im.resize([resize_h, resize_w]), np.uint8(Image.BILINEAR))

3:再运行会提示resize_h没有定义。这里不知道是不是bug。我整个把97行的transform函数改为如下:

def transform(image, input_height, input_width,
resize_height=64, resize_width=64, crop=True):
if crop:
cropped_image = center_crop(
image, input_height, input_width,
resize_height, resize_width)
h, w = image.shape[:2]
j = int(round((h - input_height) / 2.))
i = int(round((w - input_width) / 2.))
im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
else:
im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR))/127.5 - 1.

4:此时函数已经可以正常运行了,但是不能存图。

原因:utils.py中 scipy.misc.imsave被弃用

添加imageio库。用imageio.imwrite代替

大功告成!

translate version:

1:TypeError: Cannot handle this data type

Follow the code step by step crtl+b into utils.py to change line 94 to:

Im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

2: Run again; 95 lines will report error data type not understood

Change line 95 to: return np.array(im.resize([resize_h, resize_w]), np.uint8(Image.BILINEAR))

3: Re-run will prompt resize_h is not defined. I don't know if it is a bug here. I changed the 97-line transform function to the following:

Def transform(image, input_height, input_width,
Resize_height=64, resize_width=64, crop=True):
If crop:
Cropped_image = center_crop(
Image, input_height, input_width,
Resize_height, resize_width)
h, w = image.shape[:2]
j = int(round((h - input_height) / 2.))
i = int(round((w - input_width) / 2.))
Im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
Else:
Im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
Return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR))/127.5 - 1.

4: The function is now ready to run, but it cannot be saved.

Cause: scipy.misc.imsave is deprecated in utils.py

Add the imageio library. Replace with imageio.imwrite

You're done!

@Jumpleoleoleo
Copy link

changed the code became a new error...
[] Reading checkpoints... ./out\20191014.164103 - data - faces - x108.z100.uniform_signed.y64.b64\checkpoint [] Failed to find a checkpoint
[!] Load failed...
Traceback (most recent call last):
File "main.py", line 147, in
tf.app.run()
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 299, in run
_run_main(main, args)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 250, in _run_main
sys.exit(main(argv))
File "main.py", line 120, in main
dcgan.train(FLAGS)
File "H:\2019Summer\代码\DCGAN\DCGAN-tensorflow-master\model.py", line 279, in train
feed_dict={ self.inputs: batch_images, self.z: batch_z })
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
run_metadata_ptr)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1149, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (64, 96, 96, 3) for Tensor 'real_images:0', which has shape '(64, 64, 64, 3)'

Same problem!
Have you solved this problem?

Yes, from zhihu link "https://zhuanlan.zhihu.com/p/24767059" the @igoindown ’s comment,

His solution is working for me:

我运行过程中一共遇到了4个问题:

1:TypeError: Cannot handle this data type

跟着代码一步步crtl+b进utils.py把94行改为:

im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

2:再run; 95行会报错 data type not understood

把95行改为:return np.array(im.resize([resize_h, resize_w]), np.uint8(Image.BILINEAR))

3:再运行会提示resize_h没有定义。这里不知道是不是bug。我整个把97行的transform函数改为如下:

def transform(image, input_height, input_width,
resize_height=64, resize_width=64, crop=True):
if crop:
cropped_image = center_crop(
image, input_height, input_width,
resize_height, resize_width)
h, w = image.shape[:2]
j = int(round((h - input_height) / 2.))
i = int(round((w - input_width) / 2.))
im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
else:
im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR))/127.5 - 1.

4:此时函数已经可以正常运行了,但是不能存图。

原因:utils.py中 scipy.misc.imsave被弃用

添加imageio库。用imageio.imwrite代替

大功告成!

translate version:

1:TypeError: Cannot handle this data type

Follow the code step by step crtl+b into utils.py to change line 94 to:

Im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

2: Run again; 95 lines will report error data type not understood

Change line 95 to: return np.array(im.resize([resize_h, resize_w]), np.uint8(Image.BILINEAR))

3: Re-run will prompt resize_h is not defined. I don't know if it is a bug here. I changed the 97-line transform function to the following:

Def transform(image, input_height, input_width,
Resize_height=64, resize_width=64, crop=True):
If crop:
Cropped_image = center_crop(
Image, input_height, input_width,
Resize_height, resize_width)
h, w = image.shape[:2]
j = int(round((h - input_height) / 2.))
i = int(round((w - input_width) / 2.))
Im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
Else:
Im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
Return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR))/127.5 - 1.

4: The function is now ready to run, but it cannot be saved.

Cause: scipy.misc.imsave is deprecated in utils.py

Add the imageio library. Replace with imageio.imwrite

You're done!

Thank U soooo much for your help!!!

@xk88372527
Copy link

changed the code became a new error...
[] Reading checkpoints... ./out\20191014.164103 - data - faces - x108.z100.uniform_signed.y64.b64\checkpoint [] Failed to find a checkpoint [!] Load failed... Traceback (most recent call last): File "main.py", line 147, in tf.app.run() File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 299, in run _run_main(main, args) File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 250, in _run_main sys.exit(main(argv)) File "main.py", line 120, in main dcgan.train(FLAGS) File "H:\2019Summer\代码\DCGAN\DCGAN-tensorflow-master\model.py", line 279, in train feed_dict={ self.inputs: batch_images, self.z: batch_z }) File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 950, in run run_metadata_ptr) File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1149, in _run str(subfeed_t.get_shape()))) ValueError: Cannot feed value of shape (64, 96, 96, 3) for Tensor 'real_images:0', which has shape '(64, 64, 64, 3)'

Same problem! Have you solved this problem?

Yes, from zhihu link "https://zhuanlan.zhihu.com/p/24767059" the @igoindown ’s comment,

His solution is working for me:

我运行过程中一共遇到了4个问题:

1:TypeError: Cannot handle this data type

跟着代码一步步crtl+b进utils.py把94行改为:

im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

2:再run; 95行会报错 data type not understood

把95行改为:return np.array(im.resize([resize_h, resize_w]), np.uint8(Image.BILINEAR))

3:再运行会提示resize_h没有定义。这里不知道是不是bug。我整个把97行的transform函数改为如下:

def transform(image, input_height, input_width,
resize_height=64, resize_width=64, crop=True):
if crop:
cropped_image = center_crop(
image, input_height, input_width,
resize_height, resize_width)
h, w = image.shape[:2]
j = int(round((h - input_height) / 2.))
i = int(round((w - input_width) / 2.))
im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
else:
im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR))/127.5 - 1.

4:此时函数已经可以正常运行了,但是不能存图。

原因:utils.py中 scipy.misc.imsave被弃用

添加imageio库。用imageio.imwrite代替

大功告成!

translate version:

1:TypeError: Cannot handle this data type

Follow the code step by step crtl+b into utils.py to change line 94 to:

Im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

2: Run again; 95 lines will report error data type not understood

Change line 95 to: return np.array(im.resize([resize_h, resize_w]), np.uint8(Image.BILINEAR))

3: Re-run will prompt resize_h is not defined. I don't know if it is a bug here. I changed the 97-line transform function to the following:

Def transform(image, input_height, input_width,
Resize_height=64, resize_width=64, crop=True):
If crop:
Cropped_image = center_crop(
Image, input_height, input_width,
Resize_height, resize_width)
h, w = image.shape[:2]
j = int(round((h - input_height) / 2.))
i = int(round((w - input_width) / 2.))
Im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
Else:
Im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
Return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR))/127.5 - 1.

4: The function is now ready to run, but it cannot be saved.

Cause: scipy.misc.imsave is deprecated in utils.py

Add the imageio library. Replace with imageio.imwrite

You're done!

thank you!
The function is run,But there is a warning as follows:
"Lossy conversion from float64 to uint8. Range [0, 1]. Convert image to uint8 prior to saving to suppress this warning."
Will this affect the running of the program?

@George-078
Copy link

changed the code became a new error...
[] Reading checkpoints... ./out\20191014.164103 - data - faces - x108.z100.uniform_signed.y64.b64\checkpoint [] Failed to find a checkpoint
[!] Load failed...
Traceback (most recent call last):
File "main.py", line 147, in
tf.app.run()
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\app.py", line 40, in run
_run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 299, in run
_run_main(main, args)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\absl\app.py", line 250, in _run_main
sys.exit(main(argv))
File "main.py", line 120, in main
dcgan.train(FLAGS)
File "H:\2019Summer\代码\DCGAN\DCGAN-tensorflow-master\model.py", line 279, in train
feed_dict={ self.inputs: batch_images, self.z: batch_z })
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
run_metadata_ptr)
File "D:\Anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py", line 1149, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (64, 96, 96, 3) for Tensor 'real_images:0', which has shape '(64, 64, 64, 3)'

Same problem!
Have you solved this problem?

Yes, from zhihu link "https://zhuanlan.zhihu.com/p/24767059" the @igoindown ’s comment,

His solution is working for me:

我运行过程中一共遇到了4个问题:

1:TypeError: Cannot handle this data type

跟着代码一步步crtl+b进utils.py把94行改为:

im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

2:再run; 95行会报错 data type not understood

把95行改为:return np.array(im.resize([resize_h, resize_w]), np.uint8(Image.BILINEAR))

3:再运行会提示resize_h没有定义。这里不知道是不是bug。我整个把97行的transform函数改为如下:

def transform(image, input_height, input_width,
resize_height=64, resize_width=64, crop=True):
if crop:
cropped_image = center_crop(
image, input_height, input_width,
resize_height, resize_width)
h, w = image.shape[:2]
j = int(round((h - input_height) / 2.))
i = int(round((w - input_width) / 2.))
im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
else:
im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR))/127.5 - 1.

4:此时函数已经可以正常运行了,但是不能存图。

原因:utils.py中 scipy.misc.imsave被弃用

添加imageio库。用imageio.imwrite代替

大功告成!

translate version:

1:TypeError: Cannot handle this data type

Follow the code step by step crtl+b into utils.py to change line 94 to:

Im = Image.fromarray(np.uint8(x[j:j+crop_h, i:i+crop_w]))

2: Run again; 95 lines will report error data type not understood

Change line 95 to: return np.array(im.resize([resize_h, resize_w]), np.uint8(Image.BILINEAR))

3: Re-run will prompt resize_h is not defined. I don't know if it is a bug here. I changed the 97-line transform function to the following:

Def transform(image, input_height, input_width,
Resize_height=64, resize_width=64, crop=True):
If crop:
Cropped_image = center_crop(
Image, input_height, input_width,
Resize_height, resize_width)
h, w = image.shape[:2]
j = int(round((h - input_height) / 2.))
i = int(round((w - input_width) / 2.))
Im = Image.fromarray(np.uint8(image[j:j + input_height, i:i + input_width]))
Else:
Im = Image.fromarray(image[j:j+crop_h, i:i+crop_w])
Return np.array(im.resize([resize_height, resize_width]), np.uint8(Image.BILINEAR))/127.5 - 1.

4: The function is now ready to run, but it cannot be saved.

Cause: scipy.misc.imsave is deprecated in utils.py

Add the imageio library. Replace with imageio.imwrite

You're done!

你好,我根据你的修改了transform,还是会显示j,j+crop_h,i,i+crop_w未被定义,请问是什么原因呢

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

7 participants