# -*- coding: utf-8 -*-
"""read_trained_model.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1e90gyAStBf8RKtEK4im8CLO3idXdpvH5
"""

from google.colab import drive
drive.mount('/content/drive')

import tensorflow as tf

#load_trained_model
model=tf.keras.models.load_model('/content/drive/My Drive/project_saved_models/moonrock.h5')

import numpy as np
from google.colab import files
from keras.preprocessing import image
import pandas as pd

filenames = pd.read_csv('/content/test.csv')

df = pd.DataFrame(columns=['Image_File', 'Class'])
for file in filenames['Image_File']:

    fn=file

    path = '/content/Test Images/Test Images/'+fn
    img = image.load_img(path, target_size=(300, 300))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)

    images = np.vstack([x])
    classes = model.predict(images, batch_size=50)
    if classes[0]>0.5:
      print(fn + ",Small")
      df = df.append({'Image_File': fn,'Class': 'Small'}, ignore_index=True)
    else:
      print(fn + ",Large")
      df = df.append({'Image_File': fn,'Class': 'Large'}, ignore_index=True)

df

df.to_csv('Predicted_output.csv')