@@ -5,24 +5,32 @@ namespace MLTests
5
5
{
6
6
public static class ImageToVector
7
7
{
8
- public static double [ ] GetVectorOnPath ( string path )
8
+ private static float [ ] GetNormalizedVector ( float [ ] vector )
9
+ {
10
+ var max = vector . Max ( ) ;
11
+ var min = vector . Min ( ) ;
12
+ for ( var i = 0 ; i < vector . Length ; i ++ ) vector [ i ] /= max ;
13
+ return vector ;
14
+ }
15
+
16
+ public static float [ ] GetVectorOnPath ( string path )
9
17
{
10
18
var image = ImageUtil . LoadImg ( path , "grayscale" , target_size : ( 28 , 28 ) ) ;
11
19
NDarray x = ImageUtil . ImageToArray ( image ) ;
12
- //x = x.reshape(1);
13
- //x = x.reshape(78, 78, 3 );
14
- //var shape = x.shape;
20
+ var shape = x . shape ; // (28, 28, 3)
21
+ //var norm = new Keras.Layers.BatchNormalization( );
22
+
15
23
//x = x.reshape(1, x.shape[0], x.shape[1], x.shape[2]);
16
- double [ ] data = x . GetData < double > ( ) ;
24
+ float [ ] data = x . GetData < float > ( ) ;
17
25
/*
18
26
var array1 = ImageUtil.ImageToArray(image);
19
27
20
28
var array2 = np.expand_dims(array1, axis: 0);
21
29
var array3 = (NDarray)array2;
22
- double [] data = array3.GetData<double >();
30
+ float [] data = array3.GetData<float >();
23
31
*/
24
- return data ;
25
- //return new double [] { };
32
+ return GetNormalizedVector ( data ) ;
33
+ //return new float [] { };
26
34
}
27
35
}
28
36
}
0 commit comments