text: '''
  TU/e BME Project Imaging 2019
  Submission code for Kaggle PCAM
  Author: Suzanne Wetstein
  '''
  
  import os
  
  import numpy as np
  
  import glob
  import pandas as pd
  from matplotlib.pyplot import imread
  
  from keras.models import model_from_json
  
  
  TEST_PATH = '/Users/mitko/8P361/test/none/'
  MODEL_FILEPATH = 'my_first_cnn_model.json'
  MODEL_WEIGHTS_FILEPATH = 'my_first_cnn_model_weights.hdf5'
  
  # load model and model weights
  json_file = open(MODEL_FILEPATH, 'r')
  loaded_model_json = json_file.read()
  json_file.close()
  model = model_from_json(loaded_model_json)
  
  
  # load weights into new model
  model.load_weights(MODEL_WEIGHTS_FILEPATH)
  
  
  # open the test set in batches (as it is a very big dataset) and make predictions
  test_files = glob.glob(TEST_PATH + '*.tif')
  
  submission = pd.DataFrame()
  
  file_batch = 5000
  max_idx = len(test_files)
  
  for idx in range(0, max_idx, file_batch):
  
      print('Indexes: %i - %i'%(idx, idx+file_batch))
  
      test_df = pd.DataFrame({'path': test_files[idx:idx+file_batch]})
  
  
      # get the image id 
      test_df['id'] = test_df.path.map(lambda x: x.split(os.sep)[-1].split('.')[0])
      test_df['image'] = test_df['path'].map(imread)
      
      
      K_test = np.stack(test_df['image'].values)
      
      # apply the same preprocessing as during draining
      K_test = K_test.astype('float')/255.0
      
      predictions = model.predict(K_test)
      
      test_df['label'] = predictions
      submission = pd.concat([submission, test_df[['id', 'label']]])
  
  
  # save your submission
  submission.head()
  submission.to_csv('submission.csv', index = False, header = True)
  