当前位置:网站首页>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
边栏推荐
猜你喜欢
SQL optimization for advanced learning of MySQL [insert, primary key, sort, group, page, count]
92. Reverse linked list II byte skipping high frequency question
440. 字典序的第K小数字(困难)-字典树-数节点-字节跳动高频题
Go's gin framework learning
编译原理 求first集 follow集 select集预测分析表 判断符号串是否符合文法定义(有源码!!!)
Tdan over half
云原生虚拟化:基于 Kubevirt 构建边缘计算实例
958. 二叉树的完全性检验
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
MySQL进阶之索引【分类,性能分析,使用,设计原则】
随机推荐
【Appium】通过设计关键字驱动文件来编写脚本
Go file operation
92. Reverse linked list II byte skipping high frequency question
Write a regular
Type judgment in [untitled] JS
Chrome浏览器的跨域设置----包含新老版本两种设置
Index: teach you index from zero basis to proficient use
MySQL进阶之索引【分类,性能分析,使用,设计原则】
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
Halo open source project learning (II): entity classes and data tables
Operation of 2022 mobile crane driver national question bank simulation examination platform
958. Complete binary tree test
EasymodbusTCP之clientexample解析
Land cover / use data product download
Anchor location - how to set the distance between the anchor and the top of the page. The anchor is located and offset from the top
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
Submit local warehouse and synchronize code cloud warehouse
Welcome to the markdown editor