TensorFlow.NET.Samples/ImageProcessing/RetrainImageClassifierTransferLearningTFNET.cs
/// <summary>
/// Builds a list of training images from the file system.
/// </summary>
Builds a list of training images from the file system.
Builds a list of training images from the file system .
private Dictionary<string, Dictionary<string, string[]>> create_image_lists()
        {
            var sub_dirs = tf.gfile.Walk(images_folder_for_training)
                .Select(x => x.Item1)
                .OrderBy(x => x)
                .ToArray();
            var result = new Dictionary<string, Dictionary<string, string[]>>();
            foreach (var sub_dir in sub_dirs)
            {
                var dir_name = sub_dir.Split(Path.DirectorySeparatorChar).Last();
                print($"Looking for images in '{dir_name}'");
                var file_list = Directory.GetFiles(sub_dir);
                if (len(file_list) < 20)
                    print($"WARNING: Folder has less than 20 images, which may cause issues.");
                var label_name = dir_name.ToLower();
                result[label_name] = new Dictionary<string, string[]>();
                int testing_count = (int)Math.Floor(file_list.Length * testing_percentage);
                int validation_count = (int)Math.Floor(file_list.Length * validation_percentage);
                result[label_name]["testing"] = file_list.Take(testing_count).ToArray();
                result[label_name]["validation"] = file_list.Skip(testing_count).Take(validation_count).ToArray();
                result[label_name]["training"] = file_list.Skip(testing_count + validation_count).ToArray();
            }
            return result;
        }
private Dictionary < string , Dictionary < string , string [ ] > > create_image_lists ( ) { var sub_dirs = tf . gfile . Walk ( images_folder_for_training ) . Select ( x => x . Item1 ) . OrderBy ( x => x ) . ToArray ( ) ; var result = new Dictionary < string , Dictionary < string , string [ ] > > ( ) ; foreach ( var sub_dir in sub_dirs ) { var dir_name = sub_dir . Split ( Path . DirectorySeparatorChar ) . Last ( ) ; print ( $" Looking for images in ' { dir_name } ' " ) ; var file_list = Directory . GetFiles ( sub_dir ) ; if ( len ( file_list ) < 20 ) print ( $" WARNING: Folder has less than 20 images, which may cause issues. " ) ; var label_name = dir_name . ToLower ( ) ; result [ label_name ] = new Dictionary < string , string [ ] > ( ) ; int testing_count = ( int ) Math . Floor ( file_list . Length * testing_percentage ) ; int validation_count = ( int ) Math . Floor ( file_list . Length * validation_percentage ) ; result [ label_name ] [ " " ] = file_list . Take ( testing_count ) . ToArray ( ) ; result [ label_name ] [ " " ] = file_list . Skip ( testing_count ) . Take ( validation_count ) . ToArray ( ) ; result [ label_name ] [ " " ] = file_list . Skip ( testing_count + validation_count ) . ToArray ( ) ; } return result ; }
Builds a list of training images from the file system.
Builds a list of training images from the file system .