Classify images

You will be using tensorflow, ml5js,Knime or Weka in order to classify images.
Here you have a python code capable to take all the names of files in a folder and to delete empty rows in order to obtain a necessary csv to work in this project if you use Weka:


# READ ALL FILES AND PUT THE FILENAMES IN A CSV FILE
import os, csv
f=open("C:/Users/YOURNAME/Downloads/MLImages/dataset2/dataset.csv",'r+')
w=csv.writer(f)
for path, dirs, files in os.walk("C:/Users/YOURNAME/Downloads/MLImages/dataset2"):
    for filename in files:
        w.writerow([filename])

# DELETE EMPTY ROWS IN A CSV FILE     
import pandas as pd
df = pd.read_csv("C:/Users/YOURNAME/Downloads/MLImages/dataset2/dataset.csv")
df.to_csv("C:/Users/YOURNAME/Downloads/MLImages/dataset2/dataset5.csv", index=False)

# RENAME FILENAMES IN A FOLDER AUTOMATICALLY
import os
path = 'C:/Users/YOURNAME/Downloads/MLImages/dataset3'
files = os.listdir(path)
for index, file in enumerate(files):
    os.rename(os.path.join(path, file), os.path.join(path, ''.join([str(index), '.jpg'])))

# READ SEVERAL FILES IN DIFFERENT FOLDERS AND PUT IN ONLY ONE FOLDER
import shutil
import os

# Function to create new folder if not exists
def make_new_folder(folder_name, parent_folder):
	
	# Path
	path = os.path.join(parent_folder, folder_name)
	
	# Create the folder
	# 'new_folder' in
	# parent_folder
	try:
		# mode of the folder
		mode = 0o777

		# Create folder
		os.mkdir(path, mode)
	except OSError as error:
		print(error)

# current folder path
current_folder = os.getcwd()

# list of folders to be merged
list_dir = ['Folder1', 'Folder2', 'Folder3']

# enumerate on list_dir to get the
# content of all the folders ans store
# it in a dictionary
content_list = {}
for index, val in enumerate(list_dir):
	path = os.path.join(current_folder, val)
	content_list[ list_dir[index] ] = os.listdir(path)

# folder in which all the content will
# be merged
merge_folder = "merge_folder"

# merge_folder path - current_folder
# + merge_folder
merge_folder_path = os.path.join(current_folder, merge_folder)

# create merge_folder if not exists
make_new_folder(merge_folder, current_folder)

# loop through the list of folders
for sub_dir in content_list:

	# loop through the contents of the
	# list of folders
	for contents in content_list[sub_dir]:

		# make the path of the content to move
		path_to_content = sub_dir + "/" + contents

		# make the path with the current folder
		dir_to_move = os.path.join(current_folder, path_to_content )

		# move the file
		shutil.move(dir_to_move, merge_folder_path)