universalised NN class; build series-type NN
3
.gitignore
vendored
@ -144,4 +144,5 @@ cython_debug/
|
||||
# local sandbox
|
||||
sandbox/
|
||||
/algorithms/learn/decision_tree/decistion_tree.png
|
||||
/resources/data/neural_network/train
|
||||
/resources/data/neural_network/specificity/train
|
||||
/resources/data/neural_network/series/train/
|
||||
|
@ -3,14 +3,23 @@ import joblib
|
||||
import pathlib
|
||||
import tensorflow as tf
|
||||
|
||||
from enum import Enum
|
||||
from tensorflow import keras
|
||||
from tensorflow.keras import layers
|
||||
from tensorflow.keras.models import Sequential
|
||||
|
||||
|
||||
# int value is a number of classes
|
||||
class NNType(Enum):
|
||||
SERIES = "series", 4,
|
||||
SPECIFICITY = "specificity", 3
|
||||
|
||||
|
||||
class NeuralNetwork:
|
||||
def __init__(self, saved_model_path=None, classes_path=None, img_height=180, img_width=180):
|
||||
self.training_data_dir = pathlib.Path(r"../../../resources/data/neural_network/train")
|
||||
def __init__(self, network_type: NNType, saved_model_path=None, classes_path=None, img_height=180, img_width=180):
|
||||
self.type = network_type
|
||||
self.training_data_dir = pathlib.Path(fr"../../../resources/data/neural_network/{self.type.value[0]}/train")
|
||||
|
||||
self.img_height = img_height
|
||||
self.img_width = img_width
|
||||
|
||||
@ -20,7 +29,9 @@ class NeuralNetwork:
|
||||
self.model = None
|
||||
self.class_names = None
|
||||
|
||||
def build(self, num_classes=3, epochs=15, batch_size=32):
|
||||
def build(self, epochs=15, batch_size=32):
|
||||
num_classes = self.type.value[1]
|
||||
|
||||
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
|
||||
self.training_data_dir,
|
||||
validation_split=0.2,
|
||||
@ -84,8 +95,8 @@ class NeuralNetwork:
|
||||
self.model = model
|
||||
|
||||
def save(self):
|
||||
self.model.save("saved_model.h5")
|
||||
joblib.dump(self.class_names, "saved_model_classes.joblib")
|
||||
self.model.save(fr"{self.type.value[0]}/saved_model.h5")
|
||||
joblib.dump(self.class_names, fr"{self.type.value[0]}/saved_model_classes.joblib")
|
||||
|
||||
def load(self, model_path, classes_path):
|
||||
self.model = tf.keras.models.load_model(model_path)
|
||||
@ -112,13 +123,13 @@ if __name__ == "__main__":
|
||||
# Building and saving a new model:
|
||||
|
||||
# (requires a valid training set in resources/data/neural_network/train)
|
||||
# neural_network = NeuralNetwork()
|
||||
# neural_network = NeuralNetwork(NNType.SERIES)
|
||||
# neural_network.build(epochs=10)
|
||||
# neural_network.save()
|
||||
|
||||
# Loading a model from file:
|
||||
neural_network = NeuralNetwork("saved_model.h5", "saved_model_classes.joblib")
|
||||
neural_network = NeuralNetwork(NNType.SERIES, r"series/saved_model.h5", r"series/saved_model_classes.joblib")
|
||||
|
||||
# Test
|
||||
image = r"../../../resources/data/neural_network/disarm/ships/0e91bae301a5f5b136c2a0d20ef97cf6.jpg"
|
||||
image = r"../../../resources/data/neural_network/series/disarm/W/5.jpg"
|
||||
neural_network.get_answer(image)
|
||||
|
BIN
algorithms/learn/neural_network/series/saved_model.h5
Normal file
BIN
resources/data/neural_network/series/disarm/F/0.jpg
Normal file
After Width: | Height: | Size: 958 B |
BIN
resources/data/neural_network/series/disarm/F/1.jpg
Normal file
After Width: | Height: | Size: 896 B |
BIN
resources/data/neural_network/series/disarm/F/10.jpg
Normal file
After Width: | Height: | Size: 893 B |
BIN
resources/data/neural_network/series/disarm/F/100.jpg
Normal file
After Width: | Height: | Size: 987 B |
BIN
resources/data/neural_network/series/disarm/F/101.jpg
Normal file
After Width: | Height: | Size: 916 B |
BIN
resources/data/neural_network/series/disarm/F/102.jpg
Normal file
After Width: | Height: | Size: 912 B |
BIN
resources/data/neural_network/series/disarm/F/103.jpg
Normal file
After Width: | Height: | Size: 927 B |
BIN
resources/data/neural_network/series/disarm/F/104.jpg
Normal file
After Width: | Height: | Size: 900 B |
BIN
resources/data/neural_network/series/disarm/F/105.jpg
Normal file
After Width: | Height: | Size: 849 B |
BIN
resources/data/neural_network/series/disarm/F/106.jpg
Normal file
After Width: | Height: | Size: 889 B |
BIN
resources/data/neural_network/series/disarm/F/107.jpg
Normal file
After Width: | Height: | Size: 925 B |
BIN
resources/data/neural_network/series/disarm/F/108.jpg
Normal file
After Width: | Height: | Size: 910 B |
BIN
resources/data/neural_network/series/disarm/F/109.jpg
Normal file
After Width: | Height: | Size: 908 B |
BIN
resources/data/neural_network/series/disarm/F/11.jpg
Normal file
After Width: | Height: | Size: 923 B |
BIN
resources/data/neural_network/series/disarm/F/110.jpg
Normal file
After Width: | Height: | Size: 992 B |
BIN
resources/data/neural_network/series/disarm/F/111.jpg
Normal file
After Width: | Height: | Size: 899 B |
BIN
resources/data/neural_network/series/disarm/F/112.jpg
Normal file
After Width: | Height: | Size: 924 B |
BIN
resources/data/neural_network/series/disarm/F/113.jpg
Normal file
After Width: | Height: | Size: 833 B |
BIN
resources/data/neural_network/series/disarm/F/114.jpg
Normal file
After Width: | Height: | Size: 839 B |
BIN
resources/data/neural_network/series/disarm/F/115.jpg
Normal file
After Width: | Height: | Size: 884 B |
BIN
resources/data/neural_network/series/disarm/F/116.jpg
Normal file
After Width: | Height: | Size: 826 B |
BIN
resources/data/neural_network/series/disarm/F/117.jpg
Normal file
After Width: | Height: | Size: 838 B |
BIN
resources/data/neural_network/series/disarm/F/118.jpg
Normal file
After Width: | Height: | Size: 915 B |
BIN
resources/data/neural_network/series/disarm/F/119.jpg
Normal file
After Width: | Height: | Size: 883 B |
BIN
resources/data/neural_network/series/disarm/F/12.jpg
Normal file
After Width: | Height: | Size: 960 B |
BIN
resources/data/neural_network/series/disarm/F/120.jpg
Normal file
After Width: | Height: | Size: 946 B |
BIN
resources/data/neural_network/series/disarm/F/121.jpg
Normal file
After Width: | Height: | Size: 998 B |
BIN
resources/data/neural_network/series/disarm/F/122.jpg
Normal file
After Width: | Height: | Size: 928 B |
BIN
resources/data/neural_network/series/disarm/F/123.jpg
Normal file
After Width: | Height: | Size: 925 B |
BIN
resources/data/neural_network/series/disarm/F/124.jpg
Normal file
After Width: | Height: | Size: 953 B |
BIN
resources/data/neural_network/series/disarm/F/125.jpg
Normal file
After Width: | Height: | Size: 1009 B |
BIN
resources/data/neural_network/series/disarm/F/126.jpg
Normal file
After Width: | Height: | Size: 996 B |
BIN
resources/data/neural_network/series/disarm/F/127.jpg
Normal file
After Width: | Height: | Size: 953 B |
BIN
resources/data/neural_network/series/disarm/F/128.jpg
Normal file
After Width: | Height: | Size: 981 B |
BIN
resources/data/neural_network/series/disarm/F/129.jpg
Normal file
After Width: | Height: | Size: 1017 B |
BIN
resources/data/neural_network/series/disarm/F/13.jpg
Normal file
After Width: | Height: | Size: 930 B |
BIN
resources/data/neural_network/series/disarm/F/130.jpg
Normal file
After Width: | Height: | Size: 955 B |
BIN
resources/data/neural_network/series/disarm/F/131.jpg
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/data/neural_network/series/disarm/F/132.jpg
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/data/neural_network/series/disarm/F/133.jpg
Normal file
After Width: | Height: | Size: 958 B |
BIN
resources/data/neural_network/series/disarm/F/134.jpg
Normal file
After Width: | Height: | Size: 966 B |
BIN
resources/data/neural_network/series/disarm/F/135.jpg
Normal file
After Width: | Height: | Size: 882 B |
BIN
resources/data/neural_network/series/disarm/F/136.jpg
Normal file
After Width: | Height: | Size: 927 B |
BIN
resources/data/neural_network/series/disarm/F/137.jpg
Normal file
After Width: | Height: | Size: 907 B |
BIN
resources/data/neural_network/series/disarm/F/138.jpg
Normal file
After Width: | Height: | Size: 949 B |
BIN
resources/data/neural_network/series/disarm/F/139.jpg
Normal file
After Width: | Height: | Size: 1014 B |
BIN
resources/data/neural_network/series/disarm/F/14.jpg
Normal file
After Width: | Height: | Size: 962 B |
BIN
resources/data/neural_network/series/disarm/F/140.jpg
Normal file
After Width: | Height: | Size: 976 B |
BIN
resources/data/neural_network/series/disarm/F/141.jpg
Normal file
After Width: | Height: | Size: 948 B |
BIN
resources/data/neural_network/series/disarm/F/142.jpg
Normal file
After Width: | Height: | Size: 868 B |
BIN
resources/data/neural_network/series/disarm/F/143.jpg
Normal file
After Width: | Height: | Size: 936 B |
BIN
resources/data/neural_network/series/disarm/F/144.jpg
Normal file
After Width: | Height: | Size: 852 B |
BIN
resources/data/neural_network/series/disarm/F/145.jpg
Normal file
After Width: | Height: | Size: 800 B |
BIN
resources/data/neural_network/series/disarm/F/146.jpg
Normal file
After Width: | Height: | Size: 806 B |
BIN
resources/data/neural_network/series/disarm/F/147.jpg
Normal file
After Width: | Height: | Size: 991 B |
BIN
resources/data/neural_network/series/disarm/F/148.jpg
Normal file
After Width: | Height: | Size: 993 B |
BIN
resources/data/neural_network/series/disarm/F/149.jpg
Normal file
After Width: | Height: | Size: 881 B |
BIN
resources/data/neural_network/series/disarm/F/15.jpg
Normal file
After Width: | Height: | Size: 1020 B |
BIN
resources/data/neural_network/series/disarm/F/150.jpg
Normal file
After Width: | Height: | Size: 889 B |
BIN
resources/data/neural_network/series/disarm/F/151.jpg
Normal file
After Width: | Height: | Size: 961 B |
BIN
resources/data/neural_network/series/disarm/F/152.jpg
Normal file
After Width: | Height: | Size: 867 B |
BIN
resources/data/neural_network/series/disarm/F/153.jpg
Normal file
After Width: | Height: | Size: 973 B |
BIN
resources/data/neural_network/series/disarm/F/154.jpg
Normal file
After Width: | Height: | Size: 1004 B |
BIN
resources/data/neural_network/series/disarm/F/155.jpg
Normal file
After Width: | Height: | Size: 865 B |
BIN
resources/data/neural_network/series/disarm/F/156.jpg
Normal file
After Width: | Height: | Size: 850 B |
BIN
resources/data/neural_network/series/disarm/F/157.jpg
Normal file
After Width: | Height: | Size: 941 B |
BIN
resources/data/neural_network/series/disarm/F/158.jpg
Normal file
After Width: | Height: | Size: 911 B |
BIN
resources/data/neural_network/series/disarm/F/159.jpg
Normal file
After Width: | Height: | Size: 976 B |
BIN
resources/data/neural_network/series/disarm/F/16.jpg
Normal file
After Width: | Height: | Size: 991 B |
BIN
resources/data/neural_network/series/disarm/F/160.jpg
Normal file
After Width: | Height: | Size: 965 B |
BIN
resources/data/neural_network/series/disarm/F/161.jpg
Normal file
After Width: | Height: | Size: 927 B |
BIN
resources/data/neural_network/series/disarm/F/162.jpg
Normal file
After Width: | Height: | Size: 998 B |
BIN
resources/data/neural_network/series/disarm/F/163.jpg
Normal file
After Width: | Height: | Size: 961 B |
BIN
resources/data/neural_network/series/disarm/F/164.jpg
Normal file
After Width: | Height: | Size: 965 B |
BIN
resources/data/neural_network/series/disarm/F/165.jpg
Normal file
After Width: | Height: | Size: 968 B |
BIN
resources/data/neural_network/series/disarm/F/166.jpg
Normal file
After Width: | Height: | Size: 931 B |
BIN
resources/data/neural_network/series/disarm/F/167.jpg
Normal file
After Width: | Height: | Size: 958 B |
BIN
resources/data/neural_network/series/disarm/F/168.jpg
Normal file
After Width: | Height: | Size: 986 B |
BIN
resources/data/neural_network/series/disarm/F/169.jpg
Normal file
After Width: | Height: | Size: 971 B |
BIN
resources/data/neural_network/series/disarm/F/17.jpg
Normal file
After Width: | Height: | Size: 899 B |
BIN
resources/data/neural_network/series/disarm/F/170.jpg
Normal file
After Width: | Height: | Size: 879 B |
BIN
resources/data/neural_network/series/disarm/F/171.jpg
Normal file
After Width: | Height: | Size: 895 B |
BIN
resources/data/neural_network/series/disarm/F/172.jpg
Normal file
After Width: | Height: | Size: 901 B |
BIN
resources/data/neural_network/series/disarm/F/173.jpg
Normal file
After Width: | Height: | Size: 907 B |
BIN
resources/data/neural_network/series/disarm/F/174.jpg
Normal file
After Width: | Height: | Size: 861 B |
BIN
resources/data/neural_network/series/disarm/F/175.jpg
Normal file
After Width: | Height: | Size: 927 B |
BIN
resources/data/neural_network/series/disarm/F/176.jpg
Normal file
After Width: | Height: | Size: 860 B |
BIN
resources/data/neural_network/series/disarm/F/177.jpg
Normal file
After Width: | Height: | Size: 941 B |
BIN
resources/data/neural_network/series/disarm/F/178.jpg
Normal file
After Width: | Height: | Size: 900 B |
BIN
resources/data/neural_network/series/disarm/F/179.jpg
Normal file
After Width: | Height: | Size: 896 B |
BIN
resources/data/neural_network/series/disarm/F/18.jpg
Normal file
After Width: | Height: | Size: 961 B |
BIN
resources/data/neural_network/series/disarm/F/180.jpg
Normal file
After Width: | Height: | Size: 833 B |
BIN
resources/data/neural_network/series/disarm/F/181.jpg
Normal file
After Width: | Height: | Size: 894 B |
BIN
resources/data/neural_network/series/disarm/F/182.jpg
Normal file
After Width: | Height: | Size: 981 B |