I wanted to create an image classification app in python as a university project, but I get the error you can see on the pic below:
Error message: Error_image
I have 2 python files a teach.py, which teaches the pictures to the algorithm and saves it and a main.py which loads the saved model and a gui to uplad and predict the images, but when I debug I get the error don't know why neither do I know how to fix it...
You can see main.py below:
main.py:
import keras
import numpy as np
import gradio as gr
import pathlib
import os
import PIL
import tkinter as tk
import warnings
import h5py
import zipfile
import tensorflow as tf
import joblib
import globals
import matplotlib.pyplot as plt
from keras.applications import vgg16
from keras.applications.vgg16 import decode_predictions
from keras.utils import img_to_array
from tkinter import *
from keras.preprocessing.image import ImageDataGenerator
from keras.applications.vgg16 import preprocess_input
from keras.models import Sequential
from keras.layers import Dense,Flatten,Dropout
from sklearn import model_selection, datasets
from sklearn.tree import DecisionTreeClassifier
from pathlib import Path
from PIL import ImageTk, Image
from tkinter import filedialog
from tensorflow import keras
from keras import layers
from keras.models import Sequential
warnings.filterwarnings('ignore')
data_dir='birbs/birbs'
class_names = os.listdir(data_dir)
loaded_model = tf.keras.models.load_model("saved_model.h5")
def load_img():
global img, image_data
for img_display in frame.winfo_children():
img_display.destroy()
image_data = filedialog.askopenfilename(initialdir="/", title="Choose an image",
filetypes=(("all files", "*.*"), ("png files", "*.png")))
basewidth = 150 # Processing image for dysplaying
img = Image.open(image_data)
wpercent = (basewidth / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
img = ImageTk.PhotoImage(img)
file_name = image_data.split('/')
panel = tk.Label(frame, text= str(file_name[len(file_name)-1]).upper()).pack()
panel_image = tk.Label(frame, image=img).pack()
def classify():
original = Image.open(image_data)
original = original.resize((224, 224), Image.ANTIALIAS)
numpy_image = img_to_array(original)
image_batch = np.expand_dims(numpy_image, axis=0)
processed_image = vgg16.preprocess_input(image_batch.copy())
predictions = vgg_model.predict(processed_image)
label = decode_predictions(predictions)
table = tk.Label(frame, text="Top image class predictions and confidences").pack()
for i in range(0, len(label[0])):
result = tk.Label(frame, text= str(label[0][i][1]).upper() + ': ' + str(round(float(label[0][i][2])*100, 3)) + '%').pack()
root = tk.Tk()
root.title('Portable Image Classifier')
root.iconbitmap('class.ico')
root.resizable(False, False)
tit = tk.Label(root, text="Portable Image Classifier", padx=25, pady=6, font=("", 12)).pack()
canvas = tk.Canvas(root, height=500, width=500, bg='grey')
canvas.pack()
frame = tk.Frame(root, bg='white')
frame.place(relwidth=0.8, relheight=0.8, relx=0.1, rely=0.1)
chose_image = tk.Button(root, text='Choose Image',
padx=35, pady=10,
fg="white", bg="grey", command=load_img)
chose_image.pack(side=tk.LEFT)
class_image = tk.Button(root, text='Classify Image',
padx=35, pady=10,
fg="white", bg="grey", command=classify)
class_image.pack(side=tk.RIGHT)
vgg_model = vgg16.VGG16(weights='imagenet')
root.mainloop()