WIP
This commit is contained in:
parent
80443b6d0a
commit
f7a81bf281
@ -1,7 +0,0 @@
|
||||
class Encoder:
|
||||
def __init__(self, encoder):
|
||||
self.encoder = encoder
|
||||
|
||||
def train_model(self, dataset):
|
||||
|
||||
pass
|
@ -1,3 +1,32 @@
|
||||
from keras.models import Sequential, load_model
|
||||
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class NeuralNetworkEncoder:
|
||||
def __init__(self):
|
||||
pass
|
||||
def __init__(self, internal_activation_function: str, external_activation_function: str, optimizer: str, loss_function: str, image_dimension_x: int, image_dimension_y: int):
|
||||
self.model = Sequential()
|
||||
self.model.add(Conv2D(32, (3, 3), activation=internal_activation_function, input_shape=(image_dimension_x, image_dimension_y, 1)))
|
||||
self.model.add(MaxPooling2D((2, 2)))
|
||||
self.model.add(Conv2D(64, (3, 3), activation=internal_activation_function))
|
||||
self.model.add(MaxPooling2D((2, 2)))
|
||||
self.model.add(Flatten())
|
||||
self.model.add(Dense(64, activation=internal_activation_function))
|
||||
self.model.add(Dense((8, 8), activation=external_activation_function))
|
||||
self.model.compile(optimizer=optimizer, loss=loss_function)
|
||||
|
||||
def __init__(self, pretrained_weights_path: str):
|
||||
self.model = load_model(pretrained_weights_path)
|
||||
|
||||
def train(self, train_imageset: pd.DataFrame, train_quantization_dataset: pd.DataFrame, validation_dataset: pd.DataFrame, validation_quantization_dataset: pd.DataFrame, epochs: int, batch_size: int):
|
||||
self.model.fit(train_imageset, train_quantization_dataset, validation_data=(validation_dataset, validation_quantization_dataset), epochs=epochs, batch_size=batch_size)
|
||||
|
||||
def export_weights(self, output_path: str):
|
||||
self.model.save(output_path)
|
||||
|
||||
def evaluate(self, test_imageset: pd.DataFrame, test_quantization_dataset: pd.DataFrame):
|
||||
return self.model.evaluate(test_imageset, test_quantization_dataset)
|
||||
|
||||
def predict_quantization_table(self, imageset: pd.DataFrame):
|
||||
return self.model.predict(imageset)
|
||||
|
||||
|
@ -1,19 +0,0 @@
|
||||
import numpy as np
|
||||
from sklearn.ensemble import RandomForestRegressor
|
||||
from sklearn.model_selection import cross_val_score
|
||||
from sklearn.model_selection import train_test_split
|
||||
|
||||
class RandomForestEncoder:
|
||||
def __init__(self):
|
||||
self.engine = RandomForestRegressor(n_estimators=100, max_depth=10)
|
||||
self.dataset_training_X = None
|
||||
self.dataset_training_y = None
|
||||
self.dataset_testing_X = None
|
||||
self.dataset_testing_y = None
|
||||
|
||||
def train_model(self, dataset):
|
||||
self.dataset_training_X, self.dataset_training_y, self.dataset_testing_X, self.dataset_testing_y = train_test_split(dataset, test_size=0.2)
|
||||
self.engine.fit(self.dataset_training_X, self.dataset_training_y)
|
||||
|
||||
def evaluate_model(self):
|
||||
return cross_val_score(self.engine, self.dataset_testing_X, self.dataset_testing_y)
|
@ -32,6 +32,16 @@ class Dataset():
|
||||
self.dataset_filenames.append(new_filename)
|
||||
self.dataset_size = counter
|
||||
|
||||
def load_prepared_dataset(self):
|
||||
for filename in os.listdir(self.dataset_path):
|
||||
if os.path.isfile(file):
|
||||
counter += 1
|
||||
else:
|
||||
continue
|
||||
file = os.path.join(self.dataset_path, filename)
|
||||
self.dataset_filenames.append(file)
|
||||
|
||||
|
||||
def __len__(self):
|
||||
return self.dataset_size
|
||||
|
||||
|
1356
longinus/poetry.lock
generated
1356
longinus/poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -17,6 +17,8 @@ pillow = "^10.2.0"
|
||||
scipy = "^1.12.0"
|
||||
scikit-learn = "^1.4.1.post1"
|
||||
opencv-python = "^4.9.0.80"
|
||||
keras = "^3.3.3"
|
||||
keras-models = "^0.0.7"
|
||||
|
||||
|
||||
[build-system]
|
||||
|
Loading…
Reference in New Issue
Block a user