Getting error while running a classification code in keras - keras

When I run the code from the following link:
https://gist.github.com/fchollet/f35fbc80e066a49d65f1688a7e99f069#file-classifier_from_little_data_script_2-py
I get the following error:
Using TensorFlow backend. Found 2000 images belonging to 2 classes.
/home/nd/anaconda3/lib/python3.6/site-packages/PIL/TiffImagePlugin.py:692:
UserWarning: Possibly corrupt EXIF data. Expecting to read 80000 bytes
but only got 0. Skipping tag 64640 "Skipping tag %s" % (size,
len(data), tag))
I am Using Ubuntu.
Tried Solution : change 'w' to 'wb' in line 70 and 81.
Thnx in advance

This is because some of the images have corrupted exif info. You can just remove the exif info of all your images to remove this warning.
The python package piexif can help you. you can use the following code to remove the exif info of an image:
import piexif
# suppose im_path is a valid image path
piexif.remove(im_path)
You can find more discussion here.

The error seems to imply that you try to use TIFF images (rather than JPEGs) and that the PIL library canĀ“t import these without an error (Possibly corrupt EXIF data).
I suggest you try some test JPEGs to make sure your images can be imported correctly.

Related

Convert ANSYS MECHANICAL files to VTK using APDL

I have followed the script provided here by DaveD here:
How to read Ansys data files in ParaView?
But I am unable to get a result that Paraview can import. I attach a few screenshots, because several warnings came out while the script was being run. I got a vtk as output (360 MB, so I guess it contains something...), but Paraview displays the following error:
ERROR: In C:\glr\builds\paraview\paraview-ci\source-paraview\VTK\IO\Legacy\vtkUnstructuredGridReader.cxx, line 320
vtkUnstructuredGridReader (000001CECD70BC00): Unrecognized keyword: 0.00000e+00
I have never used APDL, so I will be happy if the author of the script or someone experienced using it could tell me what I did wrong (I continued clicking "yes" through all the windows and I got the output.vtk as I mentioned)
Thanks a lot in advance
enter image description here

Is there a way to ignore EXIF orientation data when loading an image with PIL?

I'm getting some unwanted rotation when loading images using PIL. I'm loading image samples and their binary mask, so this is causing issues. I'm attempting to convert the code to use openCV instead, but this is proving sticky. I haven't seen any arguments in the documentation under Image.load(), but I'm hoping there's a workaround I just haven't found...
There is, but I haven't written it all up. Basically, if you load an image with EXIF "Orientation" field set, you can get that parameter.
First, a quick test using this image from the PIL GitHub source Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg and run jhead on it you can see the EXIF orientation is 6:
jhead /Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg
File name : /Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg
File size : 4951 bytes
File date : 2020:04:24 14:00:09
Resolution : 128 x 128
Orientation : rotate 90 <--- see here
JPEG Quality : 75
Now do that in PIL:
from PIL import Image
# Load that image
im = Image.open('/Users/mark/StackOverflow/PillowBuild/Pillow-7.1.2/Tests/images/hopper_orientation_6.jpg')
# Get all EXIF data
e = im.getexif()
# Specifically get orientation
e.get(0x0112)
# prints 6
Now click on the source and you can work out how your image has been rotated and undo it.
Or, you could be completely unprofessional ;-) and create a function called SneakilyRemoveOrientationWhileNooneIsLooking(filename) and shell out (subprocess) to exiftool and remove the orientation with:
exiftool -Orientation= image.jpg
Author's "much simpler solution" detailed in above comment is misleading so I just wanna clear that up.
Pillow does not automatically apply EXIF orientation transformation when reading an image. However, it has a method to do so: PIL.ImageOps.exif_transpose(image)
OpenCV automatically applies EXIF orientation when reading an image. You can disable this behavior by using the IMREAD_IGNORE_ORIENTATION flag.
I believe the author's true intention was to apply the EXIF orientation rather than ignore it, which is exactly what his solution accomplished.

Tesseract-OCR is unable to find text in SOME images

I have been using tesseract for text extraction from images. But due to some unknown reasons, it is unable to extract text from some images even if the image is clean. I am unable to find the reason for this. Is there anything that i am missing in preprocessing?
from pytesseract import image_to_string
text = image_to_string('/path/to/image')
result: " "
this code is working fine with other images, But not with this image.
original image:

Image type Python: loaded a jpg, showing a png

I have been playing around with images in Python, just trying to understand how things work basically. I have noticed something odd and was wondering if anyone else could explain it.
I have an image 'duck.jpg' -
If I look at the properties I can see that it is a jpg image.
However, after importing into python using the follwoing convoluted way:
from PIL import Image
import io
with open('duck.jpg', 'rb') as f:
im = Image.open(io.BytesIO(f.read()))
f.close()
I get the following output after calling
im.format
'PNG'
Is there some sort of automatic conversion going on?

Trouble importing VTK files into Paraview (Error reading ascii data)

I am very new to using Paraview, and I'm trying to import a few VTK files and view them. However, I'm receiving the following errors:
Generic Warning: In /Users/kitware/dashboards/buildbot-slave/8275bd07/build/superbuild/paraview/src/VTK/IO/Legacy/vtkDataReader.cxx, line 1436
Error reading ascii data. Possible mismatch of datasize with declaration.
ERROR: In /Users/kitware/dashboards/buildbot-slave/8275bd07/build/superbuild/paraview/src/VTK/IO/Legacy/vtkUnstructuredGridReader.cxx, line 346
vtkUnstructuredGridReader (0x7fb15582bd10): Unrecognized keyword: ,
I can't seem to figure out what's wrong, I've tried converting them to other formats to no avail.
I don't think there's a problem with the files. I can open them with Paraview 5.6. Maybe they were generated with a version of VTK that is more recent than the one used for your version of Paraview. You should install the latest version of Paraview (or at least 5.6).
The big file results in some visible geometry, the smaller one does not. But I have no error message, everything seems ok.

Resources