Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import images to google colab

I'm starting to use google colab I'm I want to load a set of images for processing from my laptop.

I have tried this:

enter image description here

But I get the error:

TypeError: embedded NUL character

Which is then the right process to import the images?

like image 684
Luis Ramon Ramirez Rodriguez Avatar asked Dec 10 '22 07:12

Luis Ramon Ramirez Rodriguez


1 Answers

Try this instead.

from io import BytesIO
uploaded = files.upload()
im = Image.open(BytesIO(uploaded['test.png']))

This is because the upload() command doesn't save the file. It stores the content in uploaded dictionary.

Or you can this use this function to upload files. It will both upload and save them.

def upload_files():
  from google.colab import files
  uploaded = files.upload()
  for k, v in uploaded.items():
    open(k, 'wb').write(v)
  return list(uploaded.keys())
like image 168
korakot Avatar answered Dec 18 '22 19:12

korakot