Invalid argument: 'street_small.jpg?raw=true'


#1

Hi, trying to follow this tutorial but there is a problem.

The code bellow gives me an error: Invalid argument: ‘street_small.jpg?raw=true’

im_fname = utils.download('https://github.com/dmlc/web-data/blob/master/' +
                      'gluoncv/detection/street_small.jpg?raw=true')
x, img = data.transforms.presets.ssd.load_test(im_fname, short=512)
print('Shape of pre-processed image:', x.shape)

I’m not sure that’s the tutorial problem or mine. Hope somebody will help :slight_smile: Thanks.


#2

I cannot reproduce it in both python 2 or python 3… Do you run this code on Windows/Linux/MacOS?


#3

python 3.6.5 32-bit, Windows 7.

Here is the full message of the error:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-5-7fff98664abc> in <module>()
  1 im_fname = utils.download('https://github.com/dmlc/web-data/blob/master/' +
----> 2                           'gluoncv/detection/street_small.jpg?raw=true')
  3 x, img = data.transforms.presets.ssd.load_test(im_fname, short=512)
  4 print('Shape of pre-processed image:', x.shape)

g:\programs\languages\python36-32\lib\site-packages\gluoncv\utils\download.py in download(url, path, overwrite, sha1_hash)
 43             raise RuntimeError("Failed downloading url %s"%url)
 44         total_length = r.headers.get('content-length')
---> 45         with open(fname, 'wb') as f:
 46             if total_length is None: # no content length header
 47                 for chunk in r.iter_content(chunk_size=1024):

OSError: [Errno 22] Invalid argument: 'street_small.jpg?raw=true'

#4

Thanks for sharing.

It is a bug in gluoncv - the ? character is a reserved symbol and cannot be used in file names: https://msdn.microsoft.com/en-us/library/aa365247

As a workaround, in this particular case, you can just remove ?raw=true part from the url - it should be able to save normally.

Created an issue in the github repo: https://github.com/dmlc/gluon-cv/issues/132


#5

Actually, you can provide a second parameter to the function to define the file name on disk: path='street_small.jpg' to utils.download() function.