#! /usr/bin/env python3 # def dogs_vs_cats_data ( ): #*****************************************************************************80 # ## dogs_vs_cats_data() sets up the data files for the dogs_vs_cats computation. # # Discussion: # # The os library is used for operating system dependent activities. # In this case, we wish to create a new filename, including directory # information, using commands like # os.path.join ( directory, filename ) # # The shutil library is used for high level file operations, in this case, # shutil.copyfile ( src, dst) # copies the file src to the file dst. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 14 May 2019 # # Author: # # Original keras version by Francois Chollet; # This version by John Burkardt. # # Reference: # # Francois Chollet, # Deep Learning with Python, # Second Edition, # Manning, 2021, # ISBN: 9781617296864. # import numpy as np import os import platform import shutil print ( '' ) print ( 'dogs_vs_cats_data():' ) print ( ' python version: ' + platform.python_version ( ) ) print ( ' numpy version: ' + np.version.version ) print ( '' ) print ( ' Retrieve data for dogs_vs_cats computation.' ) print ( ' Split data into training, validation, and testing directories.' ) # # Set up the cat files. # original_cat_directory = '/home/john/public_html/datasets/cats' print ( '' ) print ( ' Copying cat data from "' + original_cat_directory + '"' ) cat_train_directory = '/home/john/public_html/keras_src/dogs_vs_cats_data/train/cats' print ( ' Creating "' + cat_train_directory + '"' ) fnames = [ 'cat.' + str(i) + '.jpg' for i in range ( 1000 ) ] for fname in fnames: src = os.path.join ( original_cat_directory, fname ) dst = os.path.join ( cat_train_directory, fname ) shutil.copyfile ( src, dst ) cat_valid_directory = '/home/john/public_html/keras_src/dogs_vs_cats_data/validation/cats' print ( ' Creating "' + cat_valid_directory + '"' ) fnames = [ 'cat.' + str(i) + '.jpg' for i in range ( 1000, 1500 ) ] for fname in fnames: src = os.path.join ( original_cat_directory, fname ) dst = os.path.join ( cat_valid_directory, fname ) shutil.copyfile ( src, dst ) cat_test_directory = '/home/john/public_html/keras_src/dogs_vs_cats_data/test/cats' print ( ' Creating "' + cat_test_directory + '"' ) fnames = [ 'cat.' + str(i) + '.jpg' for i in range ( 1500, 2500 ) ] for fname in fnames: src = os.path.join ( original_cat_directory, fname ) dst = os.path.join ( cat_test_directory, fname ) shutil.copyfile ( src, dst ) # # Set up the dog files. # original_dog_directory = '/home/john/public_html/datasets/dogs' print ( '' ) print ( ' Copying dog data from "' + original_dog_directory + '"' ) dog_train_directory = '/home/john/public_html/keras_src/dogs_vs_cats_data/train/dogs' print ( ' Creating "' + dog_train_directory + '"' ) fnames = [ 'dog.' + str(i) + '.jpg' for i in range ( 1000 ) ] for fname in fnames: src = os.path.join ( original_dog_directory, fname ) dst = os.path.join ( dog_train_directory, fname ) shutil.copyfile ( src, dst ) dog_valid_directory = '/home/john/public_html/keras_src/dogs_vs_cats_data/validation/dogs' print ( ' Creating "' + dog_valid_directory + '"' ) fnames = [ 'dog.' + str(i) + '.jpg' for i in range ( 1000, 1500 ) ] for fname in fnames: src = os.path.join ( original_dog_directory, fname ) dst = os.path.join ( dog_valid_directory, fname ) shutil.copyfile ( src, dst ) dog_test_directory = '/home/john/public_html/keras_src/dogs_vs_cats_data/test/dogs' print ( ' Creating "' + dog_test_directory + '"' ) fnames = [ 'dog.' + str(i) + '.jpg' for i in range ( 1500, 2500 ) ] for fname in fnames: src = os.path.join ( original_dog_directory, fname ) dst = os.path.join ( dog_test_directory, fname ) shutil.copyfile ( src, dst ) # # Verification: report file counts. # print ( '' ) print ( ' Sanity check, count the images:' ) print ( '' ) print ( ' cat training =', len ( os.listdir ( cat_train_directory ) ) ) print ( ' cat validation =', len ( os.listdir ( cat_valid_directory ) ) ) print ( ' cat testing =', len ( os.listdir ( cat_test_directory ) ) ) print ( '' ) print ( ' dog training =', len ( os.listdir ( dog_train_directory ) ) ) print ( ' dog validation =', len ( os.listdir ( dog_valid_directory ) ) ) print ( ' dog testing =', len ( os.listdir ( dog_test_directory ) ) ) # # Terminate. # print ( '' ) print ( 'dogs_vs_cats_data():' ) print ( ' Normal end of execution.' ) return def timestamp ( ): #*****************************************************************************80 # ## timestamp() prints the date as a timestamp. # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 06 April 2013 # # Author: # # John Burkardt # import time t = time.time ( ) print ( time.ctime ( t ) ) return None if ( __name__ == '__main__' ): timestamp ( ) dogs_vs_cats_data ( ) timestamp ( )