当前位置:网站首页>Implementation of image recognition code based on VGg convolutional neural network
Implementation of image recognition code based on VGg convolutional neural network
2022-04-23 17:53:00 【Stephen_ Tao】
VGG Model is introduced
VGG(Oxford Visual Geometry Group) The model is 2014 year ILSVRC Second place in the competition ,, from Karen Simonyan and Andrew Zisserman Realization .VGG It's a convolutional neural network model , Is in AlexNet Improvements based on .
TensorFLow Of keras Integrated in the library VGG16、VGG19 Model , You can print the structure of the model , Let's say VGG16 Take as an example to illustrate the model structure :
from tensorflow.python.keras.applications.vgg16 import VGG16
model = VGG16()
print(model.summary())
VGG Model print results
Model: "vgg16"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) [(None, 224, 224, 3)] 0
_________________________________________________________________
block1_conv1 (Conv2D) (None, 224, 224, 64) 1792
_________________________________________________________________
block1_conv2 (Conv2D) (None, 224, 224, 64) 36928
_________________________________________________________________
block1_pool (MaxPooling2D) (None, 112, 112, 64) 0
_________________________________________________________________
block2_conv1 (Conv2D) (None, 112, 112, 128) 73856
_________________________________________________________________
block2_conv2 (Conv2D) (None, 112, 112, 128) 147584
_________________________________________________________________
block2_pool (MaxPooling2D) (None, 56, 56, 128) 0
_________________________________________________________________
block3_conv1 (Conv2D) (None, 56, 56, 256) 295168
_________________________________________________________________
block3_conv2 (Conv2D) (None, 56, 56, 256) 590080
_________________________________________________________________
block3_conv3 (Conv2D) (None, 56, 56, 256) 590080
_________________________________________________________________
block3_pool (MaxPooling2D) (None, 28, 28, 256) 0
_________________________________________________________________
block4_conv1 (Conv2D) (None, 28, 28, 512) 1180160
_________________________________________________________________
block4_conv2 (Conv2D) (None, 28, 28, 512) 2359808
_________________________________________________________________
block4_conv3 (Conv2D) (None, 28, 28, 512) 2359808
_________________________________________________________________
block4_pool (MaxPooling2D) (None, 14, 14, 512) 0
_________________________________________________________________
block5_conv1 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
block5_conv2 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
block5_conv3 (Conv2D) (None, 14, 14, 512) 2359808
_________________________________________________________________
block5_pool (MaxPooling2D) (None, 7, 7, 512) 0
_________________________________________________________________
flatten (Flatten) (None, 25088) 0
_________________________________________________________________
fc1 (Dense) (None, 4096) 102764544
_________________________________________________________________
fc2 (Dense) (None, 4096) 16781312
_________________________________________________________________
predictions (Dense) (None, 1000) 4097000
=================================================================
Total params: 138,357,544
Trainable params: 138,357,544
Non-trainable params: 0
be based on VGG Image recognition
This article found two pictures of animals from the Internet , One is husky , Always a Jaguar , adopt VGG Model the image
Class identification .
Siberian Husky :
jaguar :
Code implementation
because VGG The model is integrated , So just call the corresponding API Can realize the task of image recognition .
Husky identifies
from tensorflow.python.keras.applications.vgg16 import VGG16,decode_predictions,preprocess_input
from tensorflow.python.keras.preprocessing.image import load_img,img_to_array
model = VGG16()
# Change the input picture to (224,224) Fixed size of
image = load_img("./dog.jpeg",target_size=(224,224))
# Convert the picture to 3 Dimension group
image = img_to_array(image)
# The picture becomes 4 dimension , Satisfy VGG Input requirements of the model
image = image.reshape(1,image.shape[0],image.shape[1],image.shape[2])
# Preprocess the input picture
image = preprocess_input(image)
# Predict the categories of pictures
y_predict = model.predict(image)
# Decode the prediction results
label = decode_predictions(y_predict)
res = label[0][0]
print(" The forecast category is :%s, The probability of :(%.2f%%)",(res[1],res[2]*100))
Running results
The forecast category is :Siberian_husky, The probability of :(51.18%)
Jaguar recognition
from tensorflow.python.keras.applications.vgg16 import VGG16,decode_predictions,preprocess_input
from tensorflow.python.keras.preprocessing.image import load_img,img_to_array
model = VGG16()
# Change the input picture to (224,224) Fixed size of
image = load_img("./leopard.jpg",target_size=(224,224))
# Convert the picture to 3 Dimension group
image = img_to_array(image)
# The picture becomes 4 dimension , Satisfy VGG Input requirements of the model
image = image.reshape(1,image.shape[0],image.shape[1],image.shape[2])
# Preprocess the input picture
image = preprocess_input(image)
# Predict the categories of pictures
y_predict = model.predict(image)
# Decode the prediction results
label = decode_predictions(y_predict)
res = label[0][0]
print(" The forecast category is :%s, The probability of :(%.2f%%)",(res[1],res[2]*100))
Running results
The forecast category is :leopard, The probability of :(62.83%)
summary
This paper introduces VGG Model , And based on TensorFlow.Keras Integrated in API Set the VGG Model . The accuracy of the model in the image recognition task is verified by two animal images .
版权声明
本文为[Stephen_ Tao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230548468399.html
边栏推荐
- C1 notes [task training part 2]
- 开源按键组件Multi_Button的使用,含测试工程
- Leak detection and vacancy filling (VIII)
- 122. The best time to buy and sell stocks II - one-time traversal
- Eigen learning summary
- 102. Sequence traversal of binary tree
- 198. 打家劫舍-动态规划
- 41. The first missing positive number
- ES6 new method
- Summary of floating point double precision, single precision and half precision knowledge
猜你喜欢
Applet learning notes (I)
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
Cross domain settings of Chrome browser -- including new and old versions
极致体验,揭晓抖音背后的音视频技术
2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination
958. 二叉树的完全性检验
Go语言JSON包使用
Go的Gin框架学习
JS forms the items with the same name in the array object into the same array according to the name
102. 二叉树的层序遍历
随机推荐
Sword finger offer 22 The penultimate node in the linked list - speed pointer
云原生虚拟化:基于 Kubevirt 构建边缘计算实例
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
Go的Gin框架学习
Summary of common server error codes
Halo 开源项目学习(二):实体类与数据表
1217_ Generating target files using scons
剑指 Offer 22. 链表中倒数第k个节点-快慢指针
EasymodbusTCP之clientexample解析
Cloud native Virtualization: building edge computing instances based on kubevirt
Kubernetes 服务发现 监控Endpoints
On the problem of V-IF display and hiding
2021长城杯WP
Hcip fifth experiment
Halo open source project learning (II): entity classes and data tables
JVM class loading mechanism
Land cover / use data product download
Commonly used functions -- spineros:: and spineros::)
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
ES6