from utils.utils import load_data from utils.utils import from_csv_with_filenames from utils.constants import Constants from sklearn.externals import joblib import os import logging import numpy as np csv_path = os.path.join(Constants.DATA_FOLDER, '10classes', 'audio_data.csv') LOAD = True if __name__ == '__main__': logging.info('Loading data') xs, ys, filenames = from_csv_with_filenames(csv_path) ys = [int(y) - 1000 for y in ys] vect_size = len(xs[0]) audio_som = SOM(20, 30, vect_size, n_iterations=100, checkpoint_dir=os.path.join(Constants.DATA_FOLDER, '10classes', 'audio_model', '')) if not LOAD: audio_som.train(xs) else: logging.info('Training som') audio_som.restore_trained() #audio_som.plot_som(xs, ys, plot_name='audio_som.png') showSom(audio_som, xs, ys, 1, 'Audio Map', filenames=filenames)
from models.som.SOM import SOM from models.som.SOMTest import showSom import numpy as np from utils.constants import Constants from utils.utils import from_csv_visual from sklearn.preprocessing import MinMaxScaler import os import logging visual_data_path = os.path.join(Constants.DATA_FOLDER, '10classes', 'VisualInputTrainingSet.csv') N = 1000 lenExample = 2048 if __name__ == '__main__': v_xs, v_ys = from_csv_visual(visual_data_path) v_xs = MinMaxScaler().fit_transform(v_xs) som = SOM(20, 30, lenExample, checkpoint_dir=os.path.join(Constants.DATA_FOLDER, 'visual_model_mine', ''), n_iterations=100, sigma=4.0) som.restore_trained() showSom(som, v_xs, v_ys, 1, 'Visual map')
nameInputs = list() with open(fInput, 'r') as inp: i = 0 for line in inp: if len(line) > 2: inputs[i] = (np.array(line.split(',')[1:])).astype(np.float) nameInputs.append((line.split(',')[0]).split('/')[6]) i = i + 1 print(nameInputs[0]) #get the 20x30 SOM or train a new one (if the folder does not contain the model) som = SOM(20, 30, lenExample, checkpoint_dir=os.path.join(Constants.DATA_FOLDER, 'VisualModel10classes/'), n_iterations=20, sigma=4.0) loaded = som.restore_trained() if not loaded: logging.info('Training SOM') som.train(inputs) for k in range(len(nameInputs)): nameInputs[k] = nameInputs[k].split('_')[0] #shows the SOM showSom(som, inputs, nameInputs, 1, 'Visual map')