当前位置:网站首页>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()
边栏推荐
- 4G module initialization of charge point design
- Emballage automatique et déballage compris? Quel est le principe?
- el-table X轴方向(横向)滚动条默认滑到右边
- (1) 什么是Lambda表达式
- Do you understand automatic packing and unpacking? What is the principle?
- Basic knowledge of communication interface
- Oracle数据库 SQL语句执行计划、语句跟踪与优化实例
- JS foundation - prototype prototype chain and macro task / micro task / event mechanism
- yocto 技術分享第四期:自定義增加軟件包支持
- Development of intelligent charging pile (I): overview of the overall design of the system
猜你喜欢

学习开发没有捷径,也几乎不存在带路会学的快一些的情况

Project cost management__ Topic of comprehensive calculation

Uniapp realizes global sharing of wechat applet and custom sharing button style

Pymssql controls SQL for Chinese queries

JS foundation - prototype prototype chain and macro task / micro task / event mechanism

Happy Dragon Boat Festival—— Zongzi written by canvas~~~~~

CEF download, compile project

03 fastjason solves circular references

LeetCode - 919. 完全二叉树插入器 (数组)

Getting started with JMX, MBean, mxbean, mbeanserver
随机推荐
Openeuler kernel technology sharing - Issue 1 - kdump basic principle, use and case introduction
STM32 running lantern experiment - library function version
The new series of MCU also continues the two advantages of STM32 product family: low voltage and energy saving
Problems encountered when MySQL saves CSV files
使用sed替换文件夹下文件
Swing transformer details-1
QT detection card reader analog keyboard input
An executable binary file contains more than machine instructions
2021-10-28
2021-10-27
Project cost management__ Cost management technology__ Article 7 completion performance index (tcpi)
A lottery like scissors, stone and cloth (C language)
Do you understand automatic packing and unpacking? What is the principle?
Of course, the most widely used 8-bit single chip microcomputer is also the single chip microcomputer that beginners are most easy to learn
ADS simulation design of class AB RF power amplifier
Uniapp realizes global sharing of wechat applet and custom sharing button style
应用最广泛的8位单片机当然也是初学者们最容易上手学习的单片机
Development of intelligent charging pile (I): overview of the overall design of the system
Yocto Technology Sharing Phase 4: Custom add package support
Serial communication based on 51 single chip microcomputer