mrdbourke / tensorflow-deep-learning

All course materials for the Zero to Mastery Deep Learning with TensorFlow course.
https://dbourke.link/ZTMTFcourse
MIT License
5.05k stars 2.5k forks source link

03_Conv_NN_in_TF Exercise 3 How read and save images into notebook #533

Open PatrickRooney opened 1 year ago

PatrickRooney commented 1 year ago

I'm working on Exercise 3 from 03_Conv_NN_in_TF: Take 10 photos of two different things and build your own CNN image classifier using the techniques we've built here.

I have 20 images saved in my Google drive folders (train/mugs, train/books, test/mugs, test/books) with which to build a Conv_NN classifier (see the screenshot below for the train/mugs files).

How do I read these files into my colab notebook?

I tried

!wget https://drive.google.com/drive/u/0/folders/1QLadgsowxtVp0UUWrpL3Z3cSwRsoxe8K

and it appears to read something in but

!ls 1QLadgsowxtVp0UUWrpL3Z3cSwRsoxe8K

didn't produce the expect 8 filenames but only displayed

1QLadgsowxtVp0UUWrpL3Z3cSwRsoxe8K

I don't like not seeing the folder names as I assigned them in Google drive (train/mugs). Is there any way around that?

Here's what Google drive shows for my train/mugs folder:

Screenshot from 2023-03-31 10-48-02

Thank you in advance for any code or help you can give me on how to read in these image files!

PatrickRooney commented 1 year ago

This method seems to work:

from google.colab import drive drive.mount('/content/gdrive')

Specify a path variable (project path)

train_mugs = '/content/gdrive/MyDrive/images_CNN_jpg/train/mugs/' train_books = '/content/gdrive/MyDrive/images_CNN_jpg/train/books/'

test_mugs = '/content/gdrive/MyDrive/images_CNN_jpg/test/mugs/' test_books = '/content/gdrive/MyDrive/images_CNN_jpg/test/books/'

import os os.listdir(test_mugs)

['IMG_1914.HEIC.jpg', 'IMG_1918.HEIC.jpg']

Thanks to Adam Nelson's post https://levelup.gitconnected.com/how-to-get-data-from-gdrive-into-google-colab-b0a807c01300