File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change 1
- from tensorflow .keras .applications . vgg16 import VGG16
2
- import cv2
1
+ from tensorflow .keras .preprocessing import image
2
+ from tensorflow . keras . applications . vgg16 import VGG16 , preprocess_input , decode_predictions
3
3
import numpy as np
4
4
5
- if __name__ == "__main__" :
6
- model = VGG16 ()
7
- model . summary ( )
8
- im = cv2 . resize ( cv2 . imread ( 'elephant.jpg' ),
9
- ( 224 , 224 )). astype ( np . float32 )
10
- im [:, :, 0 ] -= 103.939
11
- im [:, :, 1 ] -= 116.779
12
- im [:, :, 2 ] -= 123.68
13
- out = model . predict ( im )
14
- print (np . argmax ( out ) )
5
+ img_path = 'elephant.jpg'
6
+ model = VGG16 ()
7
+ img = image . load_img ( img_path , target_size = ( 224 , 224 ) )
8
+ x = image . img_to_array ( img )
9
+ x = np . expand_dims ( x , axis = 0 )
10
+ x = preprocess_input ( x )
11
+ model . summary ()
12
+ preds = model . predict ( x )
13
+
14
+ print ('Predicted:' , decode_predictions ( preds , top = 3 )[ 0 ] )
You can’t perform that action at this time.
0 commit comments