ValueError: Could not find a format to read the specified file in mode 'i'

Calcutta picture Calcutta · Jan 26, 2019 · Viewed 29.9k times · Source

I am trying to read a png file into a python-flask application running in docker and am getting an error that says

ValueError: Could not find a format to read the specified file in mode 'i'

i have uploaded a file using an HTML file and now i am trying to read it for further processing. i see that scipy.misc.imread is deprecated and i am trying to replace this with imageio.imread

if request.method=='POST':
    file = request.files['image']
    if not file: 
        return render_template('index.html', label="No file")
    #img = misc.imread(file)
    img = imageio.imread(file)

i get this error :

File "./appimclass.py", line 34, in make_prediction

img = imageio.imread(file)

File "/usr/local/lib/python3.6/site-packages/imageio/core/functions.py", line 221, in imread

reader = read(uri, format, "i", **kwargs)

File "/usr/local/lib/python3.6/site-packages/imageio/core/functions.py", line 139, in get_reader

"Could not find a format to read the specified file " "in mode %r" % mode

Answer

Arsene Lupin picture Arsene Lupin · Apr 28, 2019

Different, but in case helpful. I had an identical error in a different library (skimage), and the solution was to add an extra 'plugin' parameter like so -

image = io.imread(filename,plugin='matplotlib')