diff --git a/Podprojekt-CNN-Maksymilian-Kierski.md b/Podprojekt-CNN-Maksymilian-Kierski.md new file mode 100644 index 0000000..49d42ec --- /dev/null +++ b/Podprojekt-CNN-Maksymilian-Kierski.md @@ -0,0 +1,159 @@ +# Sztuczna Inteligencja 2020 - Raport z podprojektu + + +**Autor:** Maksymilian Kierski + +**Raportowany okres:** 15.05.2020-26.05.2020 + +**Wybrana metoda uczenia:** Splotowe sieci neuronowe (CNN) + +## Cel podprojektu +Celem podprojektu jest umożliwienie kelnerowi stwierdzenia czy na talerzu znajdującym się na stole jest jeszcze jedzenie, czy już go nie ma. Do tego celu zastosowałem splotowe sieci neuronowe (CNN), oraz biblioteki: + +* numpy, cv2 - tworzenie danych wejściowych +* tensorflow keras - tworzenie modelu +* tensorboard - analiza modelów + + +## Uczenie modelu + +### Dane wejściowe +Dane wejściowe składają się z dwóch rodzajów zdjęć talerzy, full - pełnych, oraz empty - pustych. +Na początku, aby nasz model mógł się nauczać potrzebujemy nasze dane wejściowe odpowiednio przetworzyć. + +``` +for category in CATEGORIES: + path = os.path.join(DATADIR, category) + class_num = CATEGORIES.index(category) + for img in os.listdir(path): + try: + img_array = cv2.imread(os.path.join(path, img), + cv2.IMREAD_GRAYSCALE) + new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) + training_data.append([new_array, class_num]) + except Exception as e: + pass +random.shuffle(training_data) +``` +Tutaj nasze dane wejściowe są odpowiednio przetwarzane. Na początku zdjęcie jest sczytywane, oraz przetwarzane aby każdy pixel był w skali szarości 0 - 255 (ponieważ kolor w tym zadaniu według mnie, nie odgrywa ważnej roli). Następnie skalowany jest do mniejszych rozmiarów i w końcu jako macierz zadeklarowanych wymiarów trafia do tablicy ze swoją etykietą. Na końcu cała tablica jest przetasowywana, aby umożliwić modelowi lepszą naukę. + +Teraz dane zostają podzielone na zestaw cech i zestaw etykiet, oraz zostają zapisane do plików za pomocą **pickle**. +``` +for features, label in training_data: + X.append(features) + y.append(label) + +pickle_in = open(relative_path + 'SavedData/X.pickle', 'rb') +X = pickle.load(pickle_in) + +pickle_in = open(relative_path + 'SavedData/y.pickle', 'rb') +y = pickle.load(pickle_in) +``` + +### Tworzenie modelu i proces jego nauki +#### Wczytywanie danych potrzebnych do nauki modelu +Na początku sczytywane są odpowiednio przygotowane dane (funkcja load_dataset) +``` +pickle_in = open(relative_path + 'SavedData/X.pickle', 'rb') +X = pickle.load(pickle_in) + +pickle_in = open(relative_path + 'SavedData/y.pickle', 'rb') +y = pickle.load(pickle_in) + +return X, y +``` +Wczytywanie danych i normalizacja X, ponieważ używam kolorów w skali szarości 0 - 255, to do normalizacji (skala 0-1) wystarczy przemnożyć każde pole macierzy przez 255. Inicjalizacja tensorboardu, który przyda się nam do analizy stworzonych przez nas modeli. +``` +X = load_dataset()[0] +y = load_dataset()[1] + +X = np.array(X).reshape(-1, IMG_SIZE, IMG_SIZE, 1) +y = np.array(y) + +X = X / 255.0 + +tenserboard = TensorBoard(log_dir='{}/logs/{}'.format(relative_path, NAME)) +``` + +#### Tworzenie sekwencyjnego modelu splotowych sieci neuronowych +Tutaj inicjalizuje model jako sekwencyjny, czyli w którym każda warstwa wykonywana jest po kolei. +``` +model = Sequential() +``` +Jako iż tworzę splotową sieć neuronową w której podstawową strukturą jest +```mermaid +graph LR +A((splot)) --> B(suma) +B --> C((splot)) +C --> D(suma) +D --> E[w pełni połączona warstwa] +E --> F[wynik] +``` +to jako pierwsze tworzę warstwę splotu i sumy. +``` +model.add(Conv2D(64, (3, 3),input_shape=X.shape[1:])) +model.add(Activation('relu')) +model.add(MaxPooling2D(pool_size=(2, 2))) +``` +Warstwa splotu opiera się na 64 filtrach, które sprawdzają pola o powierzchni 9 pixeli. +Jak działa splot? Splot to czynność polegająca na pobieraniu oryginalnych danych i tworzeniu z nich mapy cech z pól o zadeklarowanych wymiarach. Jest ich tak dużo jak pozwala na to nam całość naszych danych. +Po czym wykonywana jest funkcja aktywacyjna ReLu. +A na końcu na naszej wykonujemy pooling z atrybutem **max**, czyli z wielkości 2 na 2 z naszej warstwy splotu wybieramy największą wartość. + +W tym pod projekcie najbardziej efektywne okazało się zastosowanie dwóch takich warstw. +``` +layer size | conv layer | Dense layer | + 64 | 1 | 0 | loss: 0.0443 - accuracy: 0.9942 - val_loss: 0.3614 - val_accuracy: 0.7692 + 64 | 2 | 0 | loss: 0.0931 - accuracy: 0.9625 - val_loss: 0.4772 - val_accuracy: 0.8462 + 64 | 3 | 0 | loss: 0.2491 - accuracy: 0.9020 - val_loss: 0.3762 - val_accuracy: 0.7949 + 64 | 1 | 1 | loss: 0.0531 - accuracy: 0.9971 - val_loss: 0.4176 - val_accuracy: 0.8205 + 64 | 2 | 1 | loss: 0.0644 - accuracy: 0.9798 - val_loss: 0.5606 - val_accuracy: 0.8462 + 64 | 3 | 1 | loss: 0.1126 - accuracy: 0.9625 - val_loss: 0.5916 - val_accuracy: 0.8205 +``` +![accuracy](src/SubprojectMaksymilianKierski/Data/LogsIMG/accuracy.png) +![loss](src/SubprojectMaksymilianKierski/Data/LogsIMG/loss.png) + +W drugim przypadku nie musimy już zmieniać naszych danych ponieważ pochodzą one z poprzedniej warstwy. +``` +model.add(Conv2D(64, (3, 3),input_shape=X.shape[1:])) +model.add(Activation('relu')) +model.add(MaxPooling2D(pool_size=(2, 2))) + +model.add(Conv2D(64, (3, 3))) +model.add(Activation('relu')) +model.add(MaxPooling2D(pool_size=(2, 2))) +``` +Na koniec spłaszczam naszą trójwymiarową tablice, na macierz stosując funkcje Flatten(), oraz używam warstwę Dense z tylko jednym neuronem, który będzie naszym wynikiem. Funkcja aktywacji jest to oczywiście funkcja sigmoid ponieważ chcemy otrzymać wynik (0-1). + +``` +model.add(Flatten()) +model.add(Dense(1)) +model.add(Activation('sigmoid')) +``` +Następnie zachodzi kompilacja modelu. Używam funkcję straty **binary_crosentropy** , ponieważ mierzymy się z problemem klasyfikacji binarnej. Problem klasyfikacji binarnej jest wtedy, gdy do rozpatrzenia mamy tylko dwa przypadki, w tym zadaniu talerz z jedzeniem(0) oraz bez jedzenia(1). Optymalizator, który użyłem jest to **adam**, a za pomocą **metrics** aktywuje monitorowanie dokładności. +Kilka słów o optymalizatorze **adam** - _Adam_, jest obecnie zalecany przy większości zadań optymalizacyjnych związanych z uczeniem, ponieważ łączy on zalety Adadelty i RMSprop, a zatem lepiej radzi sobie z większością problemów. + + +Na sam koniec wywołuję funkcję uczenia, oraz zapisuję model do wykorzystania go w projekcie głównym. +``` +model.fit(X, y, batch_size=32, epochs=10, validation_split=0.1, callbacks=[tenserboard]) + +model.save(relative_path + 'SavedModels/{}.model'.format(NAME)) +``` +## Integracja z projektem + +Podprojekt wywołujemy naciskając **m** na klawiaturze, kelner wtedy wybiera losowo stolik i do niego idzie zaimplementowanym wcześniej algorytmem A*. Po dotarciu do wybranego miejsca, możemy wywołać funkcje sprawdzającą talerz **use_model_to_predict('img')** +``` +def prepare(filepath): + img_array = cv2.imread(filepath, cv2.IMREAD_GRAYSCALE) + new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) + plt.imshow(img_array, cmap=plt.cm.binary) + plt.show() + return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1) + +model = tf.keras.models.load_model(relative_path + 'SavedModels/plate-64x2-cnn.model') +prediction = model.predict([prepare(relative_path + 'TestData/' + name + '.jpg')]) +return int(prediction[0][0]) +``` +Funkcja ta konwertuję zdjęcie zadeklarowane do wylosowanego stolika oraz odpowiednio je konwertuję. Następnie ładuję zadeklarowany przez nas model, który zwraca nam odpowiednią liczbę, która w int() daje 0 lub 1. Odpowiednio 0 to talerz pełny a 1 to pusty. Dzięki czemu funkcją **text_speech()** możemy wyświetlić odpowiednią informacje na ekranie. + \ No newline at end of file diff --git a/main.py b/main.py index bd6497f..b1dd2ad 100644 --- a/main.py +++ b/main.py @@ -64,7 +64,10 @@ if __name__ == "__main__": if not [waiter.X, waiter.Y] in tabPos or go == 0: if [waiter.X, waiter.Y] in tabPos: model = 'waiter_' + waiter.direction - graphics.clear(waiter.X, waiter.Y - 1) + for x in range(-1, 2): + waiterX = waiter.X+(x*0.1) + print(waiterX) + graphics.clear(waiterX, waiter.Y - 1) rand = randrange(9) x = tabPos[rand][0] y = tabPos[rand][1] diff --git a/src/SubprojectMaksymilianKierski/Data/LogsIMG/accuracy.png b/src/SubprojectMaksymilianKierski/Data/LogsIMG/accuracy.png new file mode 100644 index 0000000..4868f77 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/LogsIMG/accuracy.png differ diff --git a/src/SubprojectMaksymilianKierski/Data/LogsIMG/loss.png b/src/SubprojectMaksymilianKierski/Data/LogsIMG/loss.png new file mode 100644 index 0000000..38f6cca Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/LogsIMG/loss.png differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/saved_model.pb b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/saved_model.pb new file mode 100644 index 0000000..986edc2 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/saved_model.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/variables/variables.data-00000-of-00001 b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/variables/variables.data-00000-of-00001 new file mode 100644 index 0000000..ecb6f7b Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/variables/variables.data-00000-of-00001 differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/variables/variables.index b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/variables/variables.index new file mode 100644 index 0000000..44c2122 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x1x1-1590498663.model/variables/variables.index differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/saved_model.pb b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/saved_model.pb new file mode 100644 index 0000000..7169488 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/saved_model.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/variables/variables.data-00000-of-00001 b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/variables/variables.data-00000-of-00001 new file mode 100644 index 0000000..8663b1c Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/variables/variables.data-00000-of-00001 differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/variables/variables.index b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/variables/variables.index new file mode 100644 index 0000000..77283c9 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x2x1-1590498759.model/variables/variables.index differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/saved_model.pb b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/saved_model.pb new file mode 100644 index 0000000..848dd71 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/saved_model.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/variables/variables.data-00000-of-00001 b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/variables/variables.data-00000-of-00001 new file mode 100644 index 0000000..5de0cb6 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/variables/variables.data-00000-of-00001 differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/variables/variables.index b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/variables/variables.index new file mode 100644 index 0000000..1bbc5cc Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3-1590498309.model/variables/variables.index differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/saved_model.pb b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/saved_model.pb new file mode 100644 index 0000000..9d77646 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/saved_model.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/variables/variables.data-00000-of-00001 b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/variables/variables.data-00000-of-00001 new file mode 100644 index 0000000..0ede68c Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/variables/variables.data-00000-of-00001 differ diff --git a/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/variables/variables.index b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/variables/variables.index new file mode 100644 index 0000000..22f865c Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/SavedModels/plate-cnn-64x3x1-1590498887.model/variables/variables.index differ diff --git a/src/SubprojectMaksymilianKierski/Data/TestData/test-1.jpg b/src/SubprojectMaksymilianKierski/Data/TestData/test-1.jpg index 4bea84e..5d1eb9a 100644 Binary files a/src/SubprojectMaksymilianKierski/Data/TestData/test-1.jpg and b/src/SubprojectMaksymilianKierski/Data/TestData/test-1.jpg differ diff --git a/src/SubprojectMaksymilianKierski/Data/TestData/test-10.jpg b/src/SubprojectMaksymilianKierski/Data/TestData/test-10.jpg index 450ef85..457b3e1 100644 Binary files a/src/SubprojectMaksymilianKierski/Data/TestData/test-10.jpg and b/src/SubprojectMaksymilianKierski/Data/TestData/test-10.jpg differ diff --git a/src/SubprojectMaksymilianKierski/Data/TestData/test-12.jpg b/src/SubprojectMaksymilianKierski/Data/TestData/test-12.jpg deleted file mode 100644 index 5d1eb9a..0000000 Binary files a/src/SubprojectMaksymilianKierski/Data/TestData/test-12.jpg and /dev/null differ diff --git a/src/SubprojectMaksymilianKierski/Data/TestData/test-14.jpg b/src/SubprojectMaksymilianKierski/Data/TestData/test-14.jpg deleted file mode 100644 index adff86e..0000000 Binary files a/src/SubprojectMaksymilianKierski/Data/TestData/test-14.jpg and /dev/null differ diff --git a/src/SubprojectMaksymilianKierski/Data/TestData/test-16.jpg b/src/SubprojectMaksymilianKierski/Data/TestData/test-16.jpg deleted file mode 100644 index 61dd954..0000000 Binary files a/src/SubprojectMaksymilianKierski/Data/TestData/test-16.jpg and /dev/null differ diff --git a/src/SubprojectMaksymilianKierski/Data/TestData/test-17.jpg b/src/SubprojectMaksymilianKierski/Data/TestData/test-17.jpg deleted file mode 100644 index 457b3e1..0000000 Binary files a/src/SubprojectMaksymilianKierski/Data/TestData/test-17.jpg and /dev/null differ diff --git a/src/SubprojectMaksymilianKierski/Data/TestData/test-18.jpg b/src/SubprojectMaksymilianKierski/Data/TestData/test-18.jpg deleted file mode 100644 index 52aea7e..0000000 Binary files a/src/SubprojectMaksymilianKierski/Data/TestData/test-18.jpg and /dev/null differ diff --git a/src/SubprojectMaksymilianKierski/Data/TestData/test-6.jpg b/src/SubprojectMaksymilianKierski/Data/TestData/test-6.jpg index 9da5098..52aea7e 100644 Binary files a/src/SubprojectMaksymilianKierski/Data/TestData/test-6.jpg and b/src/SubprojectMaksymilianKierski/Data/TestData/test-6.jpg differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/events.out.tfevents.1590498664.MacBook-Pro-Maxymilian.local.8123.185.v2 b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/events.out.tfevents.1590498664.MacBook-Pro-Maxymilian.local.8123.185.v2 new file mode 100644 index 0000000..543d3a4 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/events.out.tfevents.1590498664.MacBook-Pro-Maxymilian.local.8123.185.v2 differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/events.out.tfevents.1590498665.MacBook-Pro-Maxymilian.local.profile-empty b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/events.out.tfevents.1590498665.MacBook-Pro-Maxymilian.local.profile-empty new file mode 100644 index 0000000..a11bf6c Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/events.out.tfevents.1590498665.MacBook-Pro-Maxymilian.local.profile-empty differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.input_pipeline.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.input_pipeline.pb new file mode 100644 index 0000000..6483551 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.input_pipeline.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.kernel_stats.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.kernel_stats.pb new file mode 100644 index 0000000..e69de29 diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.overview_page.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.overview_page.pb new file mode 100644 index 0000000..5adecdb Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.overview_page.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb new file mode 100644 index 0000000..b4e9003 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.trace.json.gz b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.trace.json.gz new file mode 100644 index 0000000..ad451a9 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/train/plugins/profile/2020_05_26_15_11_05/MacBook-Pro-Maxymilian.local.trace.json.gz differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/validation/events.out.tfevents.1590498669.MacBook-Pro-Maxymilian.local.8123.1074.v2 b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/validation/events.out.tfevents.1590498669.MacBook-Pro-Maxymilian.local.8123.1074.v2 new file mode 100644 index 0000000..b3ce334 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x1x1-1590498663/validation/events.out.tfevents.1590498669.MacBook-Pro-Maxymilian.local.8123.1074.v2 differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/events.out.tfevents.1590498759.MacBook-Pro-Maxymilian.local.8480.215.v2 b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/events.out.tfevents.1590498759.MacBook-Pro-Maxymilian.local.8480.215.v2 new file mode 100644 index 0000000..a753f1d Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/events.out.tfevents.1590498759.MacBook-Pro-Maxymilian.local.8480.215.v2 differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/events.out.tfevents.1590498761.MacBook-Pro-Maxymilian.local.profile-empty b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/events.out.tfevents.1590498761.MacBook-Pro-Maxymilian.local.profile-empty new file mode 100644 index 0000000..03dee14 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/events.out.tfevents.1590498761.MacBook-Pro-Maxymilian.local.profile-empty differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.input_pipeline.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.input_pipeline.pb new file mode 100644 index 0000000..430f2df Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.input_pipeline.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.kernel_stats.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.kernel_stats.pb new file mode 100644 index 0000000..e69de29 diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.overview_page.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.overview_page.pb new file mode 100644 index 0000000..6453612 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.overview_page.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb new file mode 100644 index 0000000..319dae1 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.trace.json.gz b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.trace.json.gz new file mode 100644 index 0000000..c86b2dd Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/train/plugins/profile/2020_05_26_15_12_41/MacBook-Pro-Maxymilian.local.trace.json.gz differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/validation/events.out.tfevents.1590498768.MacBook-Pro-Maxymilian.local.8480.1182.v2 b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/validation/events.out.tfevents.1590498768.MacBook-Pro-Maxymilian.local.8480.1182.v2 new file mode 100644 index 0000000..9665d8d Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x2x1-1590498759/validation/events.out.tfevents.1590498768.MacBook-Pro-Maxymilian.local.8480.1182.v2 differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/events.out.tfevents.1590498309.MacBook-Pro-Maxymilian.local.6854.218.v2 b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/events.out.tfevents.1590498309.MacBook-Pro-Maxymilian.local.6854.218.v2 new file mode 100644 index 0000000..eff1e55 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/events.out.tfevents.1590498309.MacBook-Pro-Maxymilian.local.6854.218.v2 differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/events.out.tfevents.1590498312.MacBook-Pro-Maxymilian.local.profile-empty b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/events.out.tfevents.1590498312.MacBook-Pro-Maxymilian.local.profile-empty new file mode 100644 index 0000000..c54f046 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/events.out.tfevents.1590498312.MacBook-Pro-Maxymilian.local.profile-empty differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.input_pipeline.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.input_pipeline.pb new file mode 100644 index 0000000..d114c90 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.input_pipeline.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.kernel_stats.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.kernel_stats.pb new file mode 100644 index 0000000..e69de29 diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.overview_page.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.overview_page.pb new file mode 100644 index 0000000..5901324 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.overview_page.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb new file mode 100644 index 0000000..e05f9a7 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.trace.json.gz b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.trace.json.gz new file mode 100644 index 0000000..5634f40 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/train/plugins/profile/2020_05_26_15_05_12/MacBook-Pro-Maxymilian.local.trace.json.gz differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/validation/events.out.tfevents.1590498320.MacBook-Pro-Maxymilian.local.6854.1194.v2 b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/validation/events.out.tfevents.1590498320.MacBook-Pro-Maxymilian.local.6854.1194.v2 new file mode 100644 index 0000000..9782dc1 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3-1590498309/validation/events.out.tfevents.1590498320.MacBook-Pro-Maxymilian.local.6854.1194.v2 differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/events.out.tfevents.1590498888.MacBook-Pro-Maxymilian.local.8941.245.v2 b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/events.out.tfevents.1590498888.MacBook-Pro-Maxymilian.local.8941.245.v2 new file mode 100644 index 0000000..5190081 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/events.out.tfevents.1590498888.MacBook-Pro-Maxymilian.local.8941.245.v2 differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/events.out.tfevents.1590498890.MacBook-Pro-Maxymilian.local.profile-empty b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/events.out.tfevents.1590498890.MacBook-Pro-Maxymilian.local.profile-empty new file mode 100644 index 0000000..2c862f2 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/events.out.tfevents.1590498890.MacBook-Pro-Maxymilian.local.profile-empty differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.input_pipeline.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.input_pipeline.pb new file mode 100644 index 0000000..f4ecb02 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.input_pipeline.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.kernel_stats.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.kernel_stats.pb new file mode 100644 index 0000000..e69de29 diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.overview_page.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.overview_page.pb new file mode 100644 index 0000000..d37b16e Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.overview_page.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb new file mode 100644 index 0000000..17d79df Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.tensorflow_stats.pb differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.trace.json.gz b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.trace.json.gz new file mode 100644 index 0000000..abdb882 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/train/plugins/profile/2020_05_26_15_14_50/MacBook-Pro-Maxymilian.local.trace.json.gz differ diff --git a/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/validation/events.out.tfevents.1590498898.MacBook-Pro-Maxymilian.local.8941.1290.v2 b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/validation/events.out.tfevents.1590498898.MacBook-Pro-Maxymilian.local.8941.1290.v2 new file mode 100644 index 0000000..8cb90a4 Binary files /dev/null and b/src/SubprojectMaksymilianKierski/Data/logs/plate-cnn-64x3x1-1590498887/validation/events.out.tfevents.1590498898.MacBook-Pro-Maxymilian.local.8941.1290.v2 differ diff --git a/src/SubprojectMaksymilianKierski/PlateRecognition.py b/src/SubprojectMaksymilianKierski/PlateRecognition.py index 3fe3eda..d89d5fe 100644 --- a/src/SubprojectMaksymilianKierski/PlateRecognition.py +++ b/src/SubprojectMaksymilianKierski/PlateRecognition.py @@ -9,7 +9,7 @@ import pickle # For creating model import tensorflow as tf from tensorflow.keras.models import Sequential # to use sequential model -from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, \ +from tensorflow.keras.layers import Dense, Activation, Flatten, Conv2D, \ MaxPooling2D # elements which we need to creat our layers # For analysing model @@ -24,17 +24,20 @@ relative_path = os.path.join(current_path, 'Data/') DATADIR = relative_path + 'LearningData' CATEGORIES = ['Full', 'Empty'] # labels IMG_SIZE = 150 # specify on which size we want to transform the photos for example 50x50px -NAME = 'plate-cnn-64x2-{}'.format(int(time.time())) +NAME = 'plate-cnn-64x3x1-{}'.format(int(time.time())) training_data = [] X = [] # feature set y = [] # label set ''' -layer size | conv leyer | - 64 | 1 | loss: 0.0443 - accuracy: 0.9942 - val_loss: 0.3614 - val_accuracy: 0.7692 - 64 | 2 | loss: 0.0931 - accuracy: 0.9625 - val_loss: 0.4772 - val_accuracy: 0.8462 - 64 | 3 | +layer size | conv layer | Dense layer | + 64 | 1 | 0 | loss: 0.0443 - accuracy: 0.9942 - val_loss: 0.3614 - val_accuracy: 0.7692 + 64 | 2 | 0 | loss: 0.0931 - accuracy: 0.9625 - val_loss: 0.4772 - val_accuracy: 0.8462 + 64 | 3 | 0 | loss: 0.2491 - accuracy: 0.9020 - val_loss: 0.3762 - val_accuracy: 0.7949 -> + 64 | 1 | 1 | loss: 0.0531 - accuracy: 0.9971 - val_loss: 0.4176 - val_accuracy: 0.8205 + 64 | 2 | 1 | loss: 0.0644 - accuracy: 0.9798 - val_loss: 0.5606 - val_accuracy: 0.8462 + 64 | 3 | 1 | loss: 0.1126 - accuracy: 0.9625 - val_loss: 0.5916 - val_accuracy: 0.8205 ''' @@ -100,9 +103,7 @@ def creat_model(): model = Sequential() # initialize our model as a Sequential model - model.add(Conv2D(64, (3, 3), - input_shape=X.shape[ - 1:])) # first convolution layer 64 neurons (filters cuz it a convolutional layer), checking 3px on 3px, of 50px 50px grey img + model.add(Conv2D(64, (3, 3), input_shape=X.shape[1:])) # first convolution layer 64 neurons (filters cuz it a convolutional layer), checking 3px on 3px, of 50px 50px grey img model.add(Activation('relu')) # relu activation function model.add(MaxPooling2D(pool_size=(2, 2))) # max pooling on 2px on 2px conv2 layer to get the max value @@ -110,6 +111,10 @@ def creat_model(): model.add(Activation('relu')) model.add(MaxPooling2D(pool_size=(2, 2))) + # model.add(Conv2D(64, (3, 3))) + # model.add(Activation('relu')) + # model.add(MaxPooling2D(pool_size=(2, 2))) + model.add(Flatten()) # converts our 3D feature maps to 1D feature vectors model.add(Dense(1)) # output layer 1 output @@ -135,11 +140,12 @@ def use_model_to_predict(name): plt.show() return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 1) - model = tf.keras.models.load_model(relative_path + 'SavedModels/plate-cnn-64x1-1590497461.model') + model = tf.keras.models.load_model(relative_path + 'SavedModels/plate-64x2-cnn.model') + #model = tf.keras.models.load_model(relative_path + 'SavedModels/plate-cnn-64x1-1590497461.model') prediction = model.predict([prepare(relative_path + 'TestData/' + name + '.jpg')]) - print(prediction) - print(CATEGORIES[int(prediction[0][0])]) + #print(prediction) + #print(CATEGORIES[int(prediction[0][0])]) return int(prediction[0][0]) @@ -164,5 +170,8 @@ def text_speech(font: str, size: int, text: str, color, background, x, y, bold: # save_dataset() -#use_model_to_predict('test-0') -creat_model() +# for x in range(10): +# print(CATEGORIES[use_model_to_predict('test-{}'.format(x))]) +#creat_model() + +#python -m tensorboard.main --logdir=Data/logs \ No newline at end of file