def test_results_file_needs_to_be_a_csv_file(self, mock_isfile): params = [ 'Predictions.py', '/path/to/resnet50.h5', '/path/to/dir/images/', '/path/to/dir/save_images', 'results.txt' ] mock_isfile.return_value = True self.assertTrue('Name of the file needs to end with .csv!' in validation_util.get_errors(params))
def test_needs_to_be_h5_file(self, mock_isfile): mock_isfile.return_value = True params = [ 'Predictions.py', '/path/to/file/resnet50.txt', '/path/to/dir/images/', '/path/to/dir/save_images', 'results.csv' ] self.assertTrue( 'File should be a .h5 file!' in validation_util.get_errors(params))
def test_result_file_cant_exists_before_running_predictions( self, mock_isfile): mock_isfile.return_value = True params = [ 'Predictions.py', '/path/to/resnet50.h5', '/path/to/dir/images/', '/path/to/dir/save_images', 'results.csv' ] self.assertTrue(params[4] + " file of this name already exists!" in validation_util.get_errors(params))
def test_path_to_trained_model_needs_to_be_correct(self, mock_isfile): mock_isfile.return_value = False params = [ 'Predictions.py', '/wrong/path/to/resnet50.h5', '/path/to/dir/images/', '/path/to/dir/save_images', 'results.csv' ] self.assertTrue( params[1] + ' not a correct path!' in validation_util.get_errors(params))
def test_path_to_image_directory_needs_to_be_correct(self, mock_isdir): mock_isdir.return_value = False params = [ 'Predictions.py', '/path/to/resnet50.h5', '/path/to/wrong/dir/images/', '/path/to/dir/save_images', 'results.csv' ] self.assertTrue( params[2] + ' not a correct directory!' in validation_util.get_errors(params))
def main(arg): # set the modified tf session as backend in keras keras.backend.tensorflow_backend.set_session(get_session()) # make image save path if it doesn't exist if arg[3] is not None and not os.path.exists(arg[3]): os.makedirs(arg[3]) errors = get_errors(arg) # check that there are no errors in the given arguments if not errors: [a, trained_model_path, read_image_directory_path, save_image_directory_path, predictions_csv] = arg save_prediction_to_csv(trained_model_path, read_image_directory_path, save_image_directory_path, predictions_csv) else: print('Given arguments are wrong:') for error in errors: print(error)
def test_cant_have_too_few_arguments(self): params = ['param1', 'param2', 'param3'] self.assertTrue( "Too few arguments!" in validation_util.get_errors(params))
def test_cant_have_too_many_arguments(self): params = ['param1', 'param2', 'param3', 'param4', 'param5', 'param6'] self.assertTrue( "Too many arguments!" in validation_util.get_errors(params))