1- using System ;
2- using System . IO ;
1+ using System . IO ;
32using static Tensorflow . Binding ;
43using Tensorflow . NumPy ;
54
@@ -15,22 +14,8 @@ public IDatasetV2 paths_and_labels_to_dataset(string[] image_paths,
1514 int num_classes ,
1615 string interpolation )
1716 {
18- // option 1: will load all images into memory, not efficient
19- var images = np . zeros ( ( image_paths . Length , image_size [ 0 ] , image_size [ 1 ] , num_channels ) , np . float32 ) ;
20- for ( int i = 0 ; i < len ( images ) ; i ++ )
21- {
22- var img = tf . io . read_file ( image_paths [ i ] ) ;
23- img = tf . image . decode_image (
24- img , channels : num_channels , expand_animations : false ) ;
25- var resized_image = tf . image . resize_images_v2 ( img , image_size , method : interpolation ) ;
26- images [ i ] = resized_image . numpy ( ) ;
27- tf_output_redirect . WriteLine ( image_paths [ i ] ) ;
28- } ;
29- var img_ds = tf . data . Dataset . from_tensor_slices ( images ) ;
30-
31- // option 2: dynamic load, but has error, need to fix
32- // var path_ds = tf.data.Dataset.from_tensor_slices(image_paths);
33- // var img_ds = path_ds.map(x => path_to_image(x, image_size, num_channels, interpolation));
17+ var path_ds = tf . data . Dataset . from_tensor_slices ( image_paths ) ;
18+ var img_ds = path_ds . map ( x => path_to_image ( x , image_size , num_channels , interpolation ) ) ;
3419
3520 if ( label_mode == "int" )
3621 {
@@ -43,7 +28,7 @@ public IDatasetV2 paths_and_labels_to_dataset(string[] image_paths,
4328
4429 Tensor path_to_image ( Tensor path , Shape image_size , int num_channels , string interpolation )
4530 {
46- tf . print ( path ) ;
31+ // tf.print(path);
4732 var img = tf . io . read_file ( path ) ;
4833 img = tf . image . decode_image (
4934 img , channels : num_channels , expand_animations : false ) ;
@@ -58,18 +43,8 @@ public IDatasetV2 paths_and_labels_to_dataset(string[] image_paths,
5843 int num_classes ,
5944 int max_length = - 1 )
6045 {
61- var text = new string [ image_paths . Length ] ;
62- for ( int i = 0 ; i < text . Length ; i ++ )
63- {
64- text [ i ] = File . ReadAllText ( image_paths [ i ] ) ;
65- tf_output_redirect . WriteLine ( image_paths [ i ] ) ;
66- }
67-
68- var images = np . array ( text ) ;
69- var string_ds = tf . data . Dataset . from_tensor_slices ( images ) ;
70-
71- // var path_ds = tf.data.Dataset.from_tensor_slices(image_paths);
72- // var string_ds = path_ds.map(x => path_to_string_content(x, max_length));
46+ var path_ds = tf . data . Dataset . from_tensor_slices ( image_paths ) ;
47+ var string_ds = path_ds . map ( x => path_to_string_content ( x , max_length ) ) ;
7348
7449 if ( label_mode == "int" )
7550 {
0 commit comments