master #1
53
main.py
53
main.py
@ -1,2 +1,51 @@
|
||||
from field import *
|
||||
draw_interface()
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow import keras
|
||||
|
||||
|
||||
def normalize(image, label):
|
||||
return image / 255, label
|
||||
|
||||
|
||||
directoryTRAIN = "C:/Users/KimD/PycharmProjects/Traktor_V1/Vegetable Images/train"
|
||||
directoryVALIDATION = "C:/Users/KimD/PycharmProjects/Traktor_V1/Vegetable Images/validation"
|
||||
|
||||
train_ds = tf.keras.utils.image_dataset_from_directory(directoryTRAIN,
|
||||
seed=123, batch_size=32,
|
||||
image_size=(224, 224), color_mode='rgb')
|
||||
|
||||
val_ds = tf.keras.utils.image_dataset_from_directory(directoryVALIDATION,
|
||||
seed=123, batch_size=32,
|
||||
image_size=(224, 224), color_mode='rgb')
|
||||
|
||||
train_ds = train_ds.map(normalize)
|
||||
val_ds = val_ds.map(normalize)
|
||||
|
||||
model = keras.Sequential([
|
||||
keras.layers.Conv2D(64, (3, 3), activation='relu', input_shape=(224, 224, 3)),
|
||||
keras.layers.MaxPool2D((2, 2)),
|
||||
|
||||
keras.layers.Conv2D(128, (3, 3), activation='relu'),
|
||||
keras.layers.MaxPool2D((2, 2)),
|
||||
|
||||
keras.layers.Conv2D(256, (3, 3), activation='relu'),
|
||||
keras.layers.MaxPool2D((2, 2)),
|
||||
|
||||
keras.layers.Flatten(),
|
||||
keras.layers.Dense(1024, activation='relu'),
|
||||
keras.layers.Dense(9, activation='softmax')
|
||||
])
|
||||
|
||||
print(model.summary())
|
||||
|
||||
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
|
||||
|
||||
trainHistory = model.fit(train_ds, epochs=4, validation_data=val_ds)
|
||||
|
||||
model = keras.models.load_model("C:/Users/KimD/PycharmProjects/Traktor_V1/mode2.h5")
|
||||
|
||||
(loss, accuracy) = model.evaluate(val_ds)
|
||||
print(loss)
|
||||
print(accuracy)
|
||||
|
||||
# model.save("mode2.h5")
|
||||
|
29
proverka.py
Normal file
29
proverka.py
Normal file
@ -0,0 +1,29 @@
|
||||
import os
|
||||
import numpy as np
|
||||
import tensorflow as tf
|
||||
from tensorflow import keras
|
||||
import cv2
|
||||
|
||||
|
||||
|
||||
|
||||
directory = "C:/Users/KimD/PycharmProjects/Traktor_V1/Vegetable Images/test"
|
||||
|
||||
test_ds = tf.keras.utils.image_dataset_from_directory(directory, validation_split=0.2, image_size=(224, 224),
|
||||
subset="validation", seed=123, batch_size=32)
|
||||
|
||||
model = keras.models.load_model("C:/Users/KimD/PycharmProjects/Traktor_V1/mode2.h5")
|
||||
# predictions = model.predict(test_ds.take(32))
|
||||
class_names = test_ds.class_names
|
||||
|
||||
|
||||
img = cv2.imread('C:/Users/KimD/PycharmProjects/Traktor_V1/Vegetable Images/test/Carrot/1001.jpg')
|
||||
cv2.imshow("lala", img)
|
||||
cv2.waitKey(0)
|
||||
img = (np.expand_dims(img, 0))
|
||||
print(class_names)
|
||||
predictions = model.predict(img)
|
||||
print(predictions)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user