Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import numpy as np
- import pandas as pd
- from keras.models import load_model
- import tensorflow as tf
- from custom_keras_utils import normalize_timeseries
- from preprocess_test_samples import load_data_to_datasets
- ROOT_PATH = os.getcwd() + '\\test_samples_0'
- CLASS_NAME = 'Расслоение'
- CLASS_MAPPING = {
- 'ВИ_БезДефекта': 0,
- 'ВИ_Дефект': 1,
- 'Инородное включение': 2,
- 'Непроклей': 3,
- 'Непропитка': 4,
- 'Пресс_БезДефекта': 5,
- 'Пресс_Дефект': 6,
- 'Расслоение': 7
- }
- MODEL_NAME = 'resnet'
- MODEL_MAPPING = {
- 'lstm_fcn': 1,
- 'mlp': 2,
- 'resnet': 3
- }
- with tf.device('/GPU:0'):
- model = load_model(MODEL_NAME + '.h5')
- load_data_to_datasets(ROOT_PATH)
- X_test = pd.read_csv(ROOT_PATH + '\\test_x.csv', header=None, delimiter=' ')
- X_test = normalize_timeseries(X_test).values
- if MODEL_MAPPING[MODEL_NAME] == 3:
- X_test = np.reshape(X_test, (X_test.shape[0], 1, 1, X_test.shape[1]))
- else:
- X_test = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
- # Make predictions
- predictions = model.predict(X_test)
- # Convert predictions to class labels
- class_labels = [np.argmax(prediction) for prediction in predictions]
- false_predict = 0.0
- all_predict = 0
- for label in class_labels:
- if label != CLASS_MAPPING[CLASS_NAME]:
- false_predict += 1
- all_predict += 1
- print('Accuracy: {}%'.format((all_predict - false_predict) / all_predict * 100))
- os.remove(ROOT_PATH + '\\test_x.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement