def load_data(path,batch_size=25): all_files=utils.get_all_files(path) all_files=utils.append_path(path,all_files) images=utils.read_images(all_files) images=utils.flatten_images(images) images=map(utils.normalize,images) images=np.array(images) n_batches=get_number_of_batches(batch_size,len(images)) def get_batch(i): return images[i * batch_size: (i+1) * batch_size] batches=map(get_batch,range(n_batches)) batches = [np.array(batch) for batch in batches] print("Dataset loaded") return np.array(batches)
channel_train, y_true, channel_len = load_raw_labeled_data() # fit lda print('Model training..') classifier = lda() classifier.fit(channel_train, y_true) precision_clf = classifier.score(channel_train, y_true) prediction = classifier.predict(channel_train) balanced_acc = balanced_accuracy_score(y_true, prediction) kappa = cohen_kappa_score(y_true, prediction) # plot learning curve plot_learning_curve(classifier, 'learning curve of LDA', channel_train, y_true) print('train-accuracy: ', precision_clf) print('balanced-accuracy: ', balanced_acc) print('kappa: ', kappa) # prepare test data print('Prepare test data..') imgs = load_raw_images_data(test_data_path, rescale_ratio=0.25, preserve_range_after_rescale=True) channel_test, _ = flatten_images(imgs) print('Model predict..') predictions = classifier.predict(channel_test) print('Reconstruct..') sample_img = imgs[0] sample_img = reconstruct_image(sample_img, predictions) imsave(f'{img_save_path}/{data_id}_lda.png', sample_img)
def flatten(self): self.frames=utils.flatten_images(self.frames)