import sys import os import glob from keras.optimizers import SGD from keras.optimizers import Adam from tensorflow.keras.callbacks import TensorBoard import keras from keras.src.legacy.preprocessing.image import ImageDataGenerator from keras.callbacks import ModelCheckpoint from tensorflow.keras.callbacks import EarlyStopping import numpy as np import tensorflow from resnet50 import * import math from time import time print(os.getcwd()) path = os.getcwd() model_name='Weights/resnet50_20241024_270.h5.keras' # *************************************************** 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 the 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 real_path = os.path.realpath(path + '/' + model_name) print('Loading {model_name}'.format(model_name=real_path)) model = keras.models.load_model(real_path) # 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)