Member-only story
How to view an image from a Kaggle dataset in two lines of code
I have been endeavouring to learn computer vision predictive techniques and, I must say, there is a very steep learning curve in this niche subject of machine learning. One thing that I have learned is that every dataset is different, and it is for that reason that different coding techniques must be used for that different datasets.
For instance, I was working on Kaggle’s penguins and turtles dataset, which can be accessed here:- https://www.kaggle.com/datasets/abbymorgan/penguins-vs-turtles
The thing about this dataset was the fact that the images came in a directory unlabelled, with the labels coming in separate csv files. I had never encountered this problem before, so I had to study the code that one Kaggler kindly made public. The thing missing from his code was the fact that there were no images of any penguins or turtles, which is what I wanted to see. Why embark upon a computer vision task if no images are made available?
I therefore set about the task of viewing images of the jpg files and found that I could view the images in as little as two lines of code, which can be seen below:-
import PIL #
PIL.Image.open("/kaggle/input/penguins-vs-turtles/valid/valid/image_id_000.jpg")
An image of the image that I viewed using the code above can be seen here:-
I have a lot to learn when it comes to computer vision, but it’s nice to know that I found a relatively easy way to view the images associated with the dataset I am studying.