Sztuczna_inteligencja_gr_13/bin/Main/test_2.py

48 lines
1.1 KiB
Python
Raw Permalink Normal View History

2021-06-20 23:37:15 +02:00
from tkinter import PhotoImage
import cv2
import tensorflow as tf
import numpy as np
from keras_preprocessing.image import ImageDataGenerator
from bin.Classess.Field import Field
field = Field()
CATEGORIES = ['houses', 'other']
def prepare(filepath):
IMG_SIZE = 400
2021-06-21 12:05:41 +02:00
img_array = cv2.imread(filepath)
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE))
new_array = np.array(new_array) / 255
2021-06-20 23:37:15 +02:00
return new_array.reshape(1, IMG_SIZE, IMG_SIZE, 3)
2021-06-21 16:47:18 +02:00
model = tf.keras.models.load_model("../../files/Neural_networks/model/training_50_epochs")
2021-06-20 23:37:15 +02:00
model.summary()
2021-06-21 12:05:41 +02:00
test = prepare("E:/Projects/Pycharm Projects/sapper/files/large_images_houses/IMG_2573.png")
# test = prepare("E:/Projects/Pycharm Projects/sapper/files/large_images/IMG_3208.png")
2021-06-20 23:37:15 +02:00
pred = test
prediction = model.predict([pred])
print(prediction) # will be a list in a list.
2021-06-21 12:05:41 +02:00
house = prediction[0][0]
other = prediction[0][1]
if house > other:
prediction = 0
else:
prediction = 1
print(f'house: {house}\nother: {other}')
print(f'prediction: {prediction}')
2021-06-20 23:37:15 +02:00
print(CATEGORIES[int(prediction[0][0])])