Files
CNN/Models/model_testrunner.py
2024-02-23 00:31:11 -05:00

121 lines
3.8 KiB
Python

import sys
import os
import glob
from keras.layers.pooling import MaxPool2D
sys.path.append('c:/git/keras')
sys.path.append('c:/git/absl')
# installed
# py -mpip install numpy
# py -mpip show numpy
# py -mpip install tensorflow
# py -mpip show tensorflow
# py -mpip install matplotlib
# c:\users\skess\appdata\local\programs\python\python39\lib\site-packages
import keras
from keras.preprocessing.image import ImageDataGenerator
import numpy as np
import tensorflow
#model_name='lenet5.h5'
print(os.getcwd())
model_name='../Weights/resnet50.h5'
# *************************************************** T E S T I N G ********************************************
# This gets a 0. This is a good result
#image_path='C:/boneyard/DeepLearning/IndividualValidationCases/BAND_0_Test_BollingerBand.jpg'
# This gets 6.3385902e-12 [0]. I kind of expect this.
#image_path='C:/boneyard/DeepLearning/IndividualValidationCases/NVCR_0_Test_BollingerBand.jpg'
# This gets a 0. This is a good result because ABX_3_Training_BollingerBand.jpg exhibits the pattern we are looking for and is in teh Training set
#image_path='C:/boneyard/DeepLearning/IndividualValidationCases/ABX_3_Training_BollingerBand.jpg'
# This gets 0.9911055 This is a good result because SIG_0_Test_BollingerBand contains a downturn
#image_path='C:/boneyard/DeepLearning/IndividualValidationCases/SIG_0_Test_BollingerBand.jpg'
# *****************************************************************************************************************
# test_image = tensorflow.keras.preprocessing.image.load_img(image_path,color_mode='grayscale')
# test_array = keras.preprocessing.image.img_to_array(test_image)
# print(test_array.shape)
# batch_test_array = np.array([test_array])
# print(batch_test_array.shape)
# Load the model
model = keras.models.load_model(model_name)
# image_path='C:/boneyard/DeepLearning/IndividualValidationCases/SIG_0_Test_BollingerBand.jpg'
# test_image = tensorflow.keras.preprocessing.image.load_img(image_path,color_mode='grayscale')
# test_array = keras.preprocessing.image.img_to_array(test_image)
# print(test_array.shape)
# batch_test_array = np.array([test_array])
# print(batch_test_array.shape)
# predictions=model.predict(batch_test_array)
# print('Actual Prediction(s):',predictions)
# threshold_output = np.where(predictions > 0.5, 1, 0)
# print('Threshold output:',threshold_output)
# All files ending with .txt
#files=glob.glob("C:/boneyard/DeepLearning/ModelInputData/*.jpg")
files=glob.glob("C:/boneyard/DeepLearning/IndividualValidationCases/*.jpg")
#files=glob.glob("C:/boneyard/DeepLearning/data/VolatilityPriceContraction/*.jpg")
for file in files:
test_image = tensorflow.keras.preprocessing.image.load_img(file,color_mode='grayscale')
test_array = keras.preprocessing.image.img_to_array(test_image)
# print(test_array.shape)
batch_test_array = np.array([test_array])
# print(batch_test_array.shape)
predictions=model.predict(batch_test_array)
# print('Actual Prediction(s):',predictions)
# threshold_output = np.where(predictions < 0.00000005, 1, 0)
if type(predictions) == list:
average_prediction = sum(predictions)/len(predictions)
threshold_output = np.where(average_prediction > 0.5, 1, 0)
else :
threshold_output = np.where(predictions > 0.5, 1, 0)
# threshold_output = np.where(predictions > 0.5, 1, 0)
sstart=file.rfind("\\")+1
send=file.find("_")
symbol=file[int(sstart):int(send)]
# print('%s,%s' % (symbol,threshold_output[0][0]))
print('%s,%s -->%s %s' % (symbol,predictions,threshold_output,file))
#model.summary()
# predictions=model.predict(batch_test_array)
# print('Actual Prediction(s):',predictions)
# threshold_output = np.where(predictions > 0.5, 1, 0)
# print('Threshold output:',threshold_output)