当前位置:网站首页>Vgg16 migration learning source code
Vgg16 migration learning source code
2022-07-03 10:03:00 【Master Hao】
import tensorflow as tf
import numpy as np
import os
from matplotlib import pyplot as plt
Data enhancement
from tensorflow.keras.applications.vgg16 import VGG16
class myNet:
def init(self):
# For training data sets , Data enhancement is used
self.generatorForTrain = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255,
rotation_range=20, width_shift_range=0.2,
height_shift_range=0.2, horizontal_flip=True)
# For non training datasets , No data enhancement
self.generatorForText = tf.keras.preprocessing.image.ImageDataGenerator(
rescale=1./255)
self.train=self.generatorForTrain.flow_from_directory(“C:\Users\104005162\PycharmProjects\pythonProject\data\train”,
target_size=(150,150),batch_size=32,class_mode=“binary”,shuffle=True)
self.text=self.generatorForText.flow_from_directory(“C:\Users\104005162\PycharmProjects\pythonProject\data\validation\”,
target_size=(150,150),batch_size=32,class_mode=“binary”,shuffle=True)
self.baseModel=VGG16(include_top=False)
def getDateSets(self):
return self.train,self.text
# Modify the model
def refineBaseModel(self):
x=self.baseModel.output
x=tf.keras.layers.GlobalAveragePooling2D()(x)
x=tf.keras.layers.Dense(1024,activation='relu')(x)
x=tf.keras.layers.Dense(10,activation='softmax')(x)
self.combineModel=tf.keras.models.Model(inputs=self.baseModel.inputs,outputs=x)
def freezeModel(self):
for layer in self.baseModel.layers:
layer.trainable=False
def complie(self):
modelCkpt=tf.keras.callbacks.ModelCheckpoint('./ckpt/singlenn_{epoch:02d}-{val_acc:.2f}.h5',monitor="val_acc",save_weights_only=True,save_best_only=True,period=1)
self.combineModel.fit_generator(self.train,epochs=3,validation_data=self.text,callbacks=[modelCkpt])
def fit(self):
self.combineModel.fit_generator(self.train,epochs=3,validation_data=self.text)
# The following code tests the data set printing of neural network .
dataTool=myNet()
dataTool.getDateSets()
dataTool.freezeModel()
dataTool.refineBaseModel()
dataTool.complie()
dataTool.fit()
边栏推荐
- Adaptiveavgpool1d internal implementation
- I think all friends should know that the basic law of learning is: from easy to difficult
- There is no specific definition of embedded system
- 使用密钥对的形式连接阿里云服务器
- Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn
- Google browser plug-in recommendation
- uniapp 实现微信小程序全局分享及自定义分享按钮样式
- 单片机职业发展:能做下去的都成牛人了,熬不动就辞职或者改行了
- The third paper of information system project manager in soft examination
- Swing transformer details-1
猜你喜欢
How does the memory database give full play to the advantages of memory?
uniapp 实现微信小程序全局分享及自定义分享按钮样式
The third paper of information system project manager in soft examination
Notes on C language learning of migrant workers majoring in electronic information engineering
内存数据库究竟是如何发挥内存优势的?
[untitled] proteus simulation of traffic lights based on 89C51 Single Chip Microcomputer
Fundamentals of Electronic Technology (III)__ Chapter 1 resistance of parallel circuit
Swing transformer details-2
[combinatorics] Introduction to Combinatorics (combinatorial idea 3: upper and lower bound approximation | upper and lower bound approximation example Remsey number)
LeetCode - 508. 出现次数最多的子树元素和 (二叉树的遍历)
随机推荐
My notes on the development of intelligent charging pile (III): overview of the overall design of the system software
一个可执行的二进制文件包含的不仅仅是机器指令
In third tier cities and counties, it is difficult to get 10K after graduation
Problems encountered when MySQL saves CSV files
I didn't think so much when I was in the field of single chip microcomputer. I just wanted to earn money to support myself first
Seven sorting of ten thousand words by hand (code + dynamic diagram demonstration)
4G module designed by charging pile obtains signal strength and quality
STM32 general timer 1s delay to realize LED flashing
When you need to use some functions of STM32, but 51 can't realize them, 32 naturally doesn't need to learn
单片机学到什么程度能找到工作,这个标准不好量化
Pymssql controls SQL for Chinese queries
SCM is now overwhelming, a wide variety, so that developers are overwhelmed
01 business structure of imitation station B project
openEuler kernel 技术分享 - 第1期 - kdump 基本原理、使用及案例介绍
Open Euler Kernel Technology Sharing - Issue 1 - kdump Basic Principles, use and Case Introduction
Application of 51 single chip microcomputer timer
2020-08-23
Uniapp realizes global sharing of wechat applet and custom sharing button style
There is no specific definition of embedded system
Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)