def resize(path_all, path_resize, mode): image_names_dir = os.listdir(path_all) if mode == 'Test_Frame': image_names_dir = os.listdir(path_all + 'No_Fire') image_names_dir.sort() new_width = new_size.get('width') new_height = new_size.get('height') dimension = (new_width, new_height) count = 0 for image in image_names_dir: if mode == 'Fire': img = cv2.imread(path_all + '/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) cv2.imwrite(path_resize + '/resized_' + image, resized_img) elif mode == 'Lake_Mary': img = cv2.imread(path_all + '/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) cv2.imwrite(path_resize + '/lake_resized_' + image, resized_img) elif mode == 'Test_Frame': img = cv2.imread(path_all + 'No_Fire/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) cv2.imwrite(path_resize + 'No_Fire/resized_' + image, resized_img) print('Image after Resizing ' + str(count) + ' : resized_' + image) count += 1
def resize(path_all, path_resize, mode): """ Resizing the imported images to the project and save them on drive based on the dimension parameter. :param path_all: The directory of loaded images to the project :param path_resize: The directory to save the resized files :param mode: Fire, No_Fire(lake mary), or the test data :return: None """ image_names_dir = os.listdir(path_all) if mode == 'Test_Frame': # image_names_dir = os.listdir(path_all + 'Fire') # This is for the FIRE DIR (Test) image_names_dir = os.listdir( path_all + 'No_Fire') # This is for the No_FIRE DIR (Test) image_names_dir.sort() new_width = new_size.get('width') new_height = new_size.get('height') dimension = (new_width, new_height) count = 0 for image in image_names_dir: # print(resized_img.shape) # cv2.imshow('output', resized_img) if mode == 'Fire': img = cv2.imread(path_all + '/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) cv2.imwrite(path_resize + '/resized_' + image, resized_img) elif mode == 'Lake_Mary': img = cv2.imread(path_all + '/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) cv2.imwrite(path_resize + '/lake_resized_' + image, resized_img) elif mode == 'Test_Frame': # img = cv2.imread(path_all + 'Fire/' + image) img = cv2.imread(path_all + 'No_Fire/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) # cv2.imwrite(path_resize + 'Fire/resized_' + image, resized_img) # Resize for Fire (Test Data) cv2.imwrite(path_resize + 'No_Fire/resized_' + image, resized_img) # Resize for NoFire (Test Data) print('Image Resized ' + str(count) + ' : resized_' + image) count += 1
def resize(path_all, path_resize, mode): #Function to resize image_names_dir = os.listdir(path_all) if mode == 'Test_Frame': # image_names_dir = os.listdir(path_all + 'Fire') # This is for the FIRE DIR (Test) image_names_dir = os.listdir( path_all + 'No_Fire') # This is for the No_FIRE DIR (Test) image_names_dir.sort() new_width = new_size.get('width') new_height = new_size.get('height') dimension = (new_width, new_height) count = 0 for image in image_names_dir: # print(resized_img.shape) # cv2.imshow('output', resized_img) if mode == 'Fire': img = cv2.imread(path_all + '/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) cv2.imwrite(path_resize + '/resized_' + image, resized_img) elif mode == 'Lake_Mary': img = cv2.imread(path_all + '/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) cv2.imwrite(path_resize + '/lake_resized_' + image, resized_img) elif mode == 'Test_Frame': # img = cv2.imread(path_all + 'Fire/' + image) img = cv2.imread(path_all + 'No_Fire/' + image) resized_img = cv2.resize(img, dimension, interpolation=cv2.INTER_AREA) # cv2.imwrite(path_resize + 'Fire/resized_' + image, resized_img) # Resize for Fire (Test Data) cv2.imwrite(path_resize + 'No_Fire/resized_' + image, resized_img) # Resize for NoFire (Test Data) print('Image Resized ' + str(count) + ' : resized_' + image) count += 1
OS: Ubuntu 18.04 ################################ """ ######################################################### # import libraries import numpy as np import tensorflow as tf from tensorflow.keras.models import load_model from plotdata import plot_confusion_matrix from config import Config_classification from config import new_size batch_size = Config_classification.get('batch_size') image_size = (new_size.get('width'), new_size.get('height')) epochs = Config_classification.get('Epochs') ######################################################### # Function definition def classify(): """ This function load the trained model from the previous task and evaluates the performance of that over the test data set. :return: None, Plot the Confusion matrix for the test data on the binary classification """ test_ds = tf.keras.preprocessing.image_dataset_from_directory( "frames/Test", seed=1337,