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.

TypeError: long() argument must be a string or a number, not 'JpegImageFile'

See original GitHub issue

when I run :python download_and_convert_data.py `>> Converting image 23751/82783 shard 11

Converting image 23801/82783 shard 11 Converting image 23851/82783 shard 11 None Annotations data/coco/train2014/COCO_train2014_000000167118.jpg Traceback (most recent call last): File “download_and_convert_data.py”, line 36, in <module> tf.app.run() File “/mnt/data1/daniel/tensorflow/_python_build/tensorflow/python/platform/app.py”, line 48, in run _sys.exit(main(_sys.argv[:1] + flags_passthrough)) File “download_and_convert_data.py”, line 30, in main download_and_convert_coco.run(FLAGS.dataset_dir) File “/mnt/data1/daniel/codes/FastMaskRCNN/libs/datasets/download_and_convert_coco.py”, line 338, in run ‘train2014’) File “/mnt/data1/daniel/codes/FastMaskRCNN/libs/datasets/download_and_convert_coco.py”, line 299, in _add_to_tfrecord img = img.astype(np.uint8) TypeError: long() argument must be a string or a number, not ‘JpegImageFile’`

why this happened?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:25 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
kevinkitcommented, Apr 27, 2017

An idea for further investigation:

  1. Try to replace Image.open with cv2.imread, to do so you must install opencv (pip install opencv-python)

If this fixes the error there is an issue with PIL alternatively you could also try it with scipy to load the images

  1. If this does not help make a try except block around the code and check which images give you the exception, either if it is all images or just some or even just one image.

  2. Update all libs etc.

3reactions
tweedmorriscommented, Apr 27, 2017

@kevinkit Good idea about the cv2.imread – be aware though that OpenCV will load the image in BGR byte order rather than RGB, so you’ll need to switch the byte order, and perhaps make a copy of the re-strided array just in case there are any downstream functions that are expecting contiguous data:

img = cv2.imread("image.jpg").astype(np.uint8)[:,:,::-1]
img = np.ascontiguousarray(img)

Note that although OpenCV does provide a separate image I/O library, the imread/imsave functions in scipy are just fairly thin wrappers around the PIL/Pillow library so you would expect the same error as before:

>>> from scipy.misc import imread
>>> imread("truncated.jpg")
array(<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=637x800 at 0x11CB5FFD0>, dtype=object)

@Designbook1 Hope you’ve solved the problem, please do let us know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: long() argument must be a string or a number ...
long() argument must be a string or a number, not 'NoneType' means one of the arguments of feed_dict={image_tensor:image_np_expanded} has value ...
Read more >
Keras CNN TypeError: float() argument must be a string or ...
I try to set up a multiclass CNN with Keras which relies on ImageDataGenerator and flow_from_directory .
Read more >
Check All Dataset (Size and Missing) | 1 of 4
... TypeError: long() argument must be a string or a number, not 'JpegImageFile' cv2.cvtColor(numpy.array(PIL.Image.open(open(abspath_img, 'rb')), ...
Read more >
FastMaskRCNN
... :float() argument must be a string or a number, not 'JpegImageFile' Who can ... with tf.device('/gpu:%d' % i): # this should be...
Read more >
int() argument must be a string or real number, not 'list'
The Python TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType' occurs when we pass a...
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