当前位置:网站首页>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
边栏推荐
- On the method of outputting the complete name of typeID from GCC
- The method of changing a value in the array and a value in the object of wechat applet
- Double pointer advanced -- leetcode title -- container with the most water
- JS implementation private attribute
- Commonly used functions -- spineros:: and spineros::)
- 01 - get to know the advantages of sketch sketch
- Eigen learning summary
- ES6 face test questions (reference documents)
- 干货 | 快速抽取缩略图是怎么练成的?
- Go language JSON package usage
猜你喜欢
Dry goods | how to extract thumbnails quickly?
Remember using Ali Font Icon Library for the first time
Eigen learning summary
394. 字符串解码-辅助栈
Operation of 2022 mobile crane driver national question bank simulation examination platform
Welcome to the markdown editor
2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
958. Complete binary tree test
Go language JSON package usage
Uniapp custom search box adaptation applet alignment capsule
随机推荐
402. 移掉 K 位数字-贪心
440. The k-th small number of dictionary order (difficult) - dictionary tree - number node - byte skipping high-frequency question
This point in JS
2022 Shanghai safety officer C certificate operation certificate examination question bank and simulation examination
The ultimate experience, the audio and video technology behind the tiktok
2021 Great Wall Cup WP
Submit local warehouse and synchronize code cloud warehouse
2022年流动式起重机司机国家题库模拟考试平台操作
[binary number] maximum depth of binary tree + maximum depth of n-ary tree
On the method of outputting the complete name of typeID from GCC
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag
Nat Commun|在生物科学领域应用深度学习的当前进展和开放挑战
Encapsulate a timestamp to date method on string prototype
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
386. Dictionary order (medium) - iteration - full arrangement
C1 notes [task training chapter I]
Open source key component multi_ Button use, including test engineering
48. Rotate image
31. Next arrangement
Dry goods | how to extract thumbnails quickly?