TypeError: long() argument must be a string or a number, not 'JpegImageFile'
See original GitHub issuewhen 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:
- Created 6 years ago
- Comments:25 (2 by maintainers)
An idea for further investigation:
Image.open
withcv2.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
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.
Update all libs etc.
@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:
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:
@Designbook1 Hope you’ve solved the problem, please do let us know.