unpackAI / DL201

Deep learning 201
6 stars 5 forks source link

Orientation_notebook #6

Open mmrmas opened 2 years ago

mmrmas commented 2 years ago

I had an issue with the urllib.request.urlretrieve function. It downloaded the sample-cat.jpg file without error messages but stored it as a corrupted file. I borrowed the requests.get() code from one of the blocks below to make it work.

# Download the image by using its url and filename
# One of several methods to donwload an image

# create directory that is visible from browser 
try:
    os.makedirs("/kaggle/working/inferenceImages/")
except:
    print("directory already exists")   
os.chdir("/kaggle/working/inferenceImages/")

# Upload the image 
image_object = requests.get(image_url).content
with open(image_filename, 'wb') as handler:
    handler.write(image_object)

#image_data = PILImage.create(image_filename)

Note that I changed the working directory to make the files visible in the browser Note that it's not essential to generate the variable _imagedata , the model will also accept the jpg file name under _imagefilename . But this may be different for other datatypes, perhaps The model can now be called by prediction_label, p, probabilities = image_learner.predict(image_filename)

jamescavanagh commented 2 years ago

Ok, could you please send the url that you are downloading the image from?

lenismerino commented 2 years ago

@mmrmas Yes, this issue was created intentionally to give the students a reason to use the issues section, using requests.get is a preferred method to get the image, also the hosting site used to upload the image provides several links and not all of them work with urllib.request.urlretrieve.

temp

Using the cells below, try a different link and request.get and it should work,

mmrmas commented 2 years ago

@jamescavanagh this was the file: https://github.com/mmrmas/ant/blob/master/orientation-notebook-local.ipynb

jamescavanagh commented 2 years ago

Ok, great, so you did the right thing by creating an issue from the intentionally created error! Well done!