i have multiple folders in a directory and in each of the folder are hundred of images(.jpg).
Now i try to create a csv file, which includes the name of the image, a comma and then the label of it.
So my folders are
dog cat mouse elephant
and in these are images titled dog1.jpg, dog2.jpg, ... cat1.jpg, and so on.
I have already tried to list all the names of the pictures with the following code:
import os
path = '/content../'
files = []
for r, d, f in os.walk(path):
for file in f:
if '.jpg' in file:
print(file)
This prints me the list of my images. My thoughts are that i create something like
import csv
# csv file name
with open('test.csv')
category []
if filename == 'dog' then append 0
if filename == 'cat' then append 1 ...
But I am getting nowhere.
At the end the csv file should look like:
dog1.jpg,0
dog2.jpg,0
cat1.jpg,1
mouse2.jpg,2
elepant.jpg,3
I hope you can help me, Thank you very much!