当前位置: 首页 > news >正文

如何查询网站备案时间查询上海seo培训中心

如何查询网站备案时间查询,上海seo培训中心,网站改版设计流程,邯郸商城型网站建设文章目录 一、前言二、前期工作1. 设置GPU(如果使用的是CPU可以忽略这步)2. 导入数据3. 查看数据 二、数据预处理1. 加载数据2. 再次检查数据3. 配置数据集4. 可视化数据 三、构建VG-16网络四、编译五、训练模型六、模型评估七、保存and加载模型八、预测…

文章目录

  • 一、前言
  • 二、前期工作
    • 1. 设置GPU(如果使用的是CPU可以忽略这步)
    • 2. 导入数据
    • 3. 查看数据
  • 二、数据预处理
    • 1. 加载数据
    • 2. 再次检查数据
    • 3. 配置数据集
    • 4. 可视化数据
  • 三、构建VG-16网络
  • 四、编译
  • 五、训练模型
  • 六、模型评估
  • 七、保存and加载模型
  • 八、预测

一、前言

我的环境:

  • 语言环境:Python3.6.5
  • 编译器:jupyter notebook
  • 深度学习环境:TensorFlow2.4.1

往期精彩内容:

  • 卷积神经网络(CNN)实现mnist手写数字识别
  • 卷积神经网络(CNN)多种图片分类的实现
  • 卷积神经网络(CNN)衣服图像分类的实现
  • 卷积神经网络(CNN)鲜花识别
  • 卷积神经网络(CNN)天气识别
  • 卷积神经网络(VGG-16)识别海贼王草帽一伙
  • 卷积神经网络(ResNet-50)鸟类识别
  • 卷积神经网络(AlexNet)鸟类识别
  • 卷积神经网络(CNN)识别验证码

来自专栏:机器学习与深度学习算法推荐

二、前期工作

1. 设置GPU(如果使用的是CPU可以忽略这步)

import tensorflow as tfgpus = tf.config.list_physical_devices("GPU")if gpus:tf.config.experimental.set_memory_growth(gpus[0], True)  #设置GPU显存用量按需使用tf.config.set_visible_devices([gpus[0]],"GPU")# 打印显卡信息,确认GPU可用
print(gpus)

2. 导入数据

import matplotlib.pyplot as plt
# 支持中文
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False  # 用来正常显示负号import os,PIL# 设置随机种子尽可能使结果可以重现
import numpy as np
np.random.seed(1)# 设置随机种子尽可能使结果可以重现
import tensorflow as tf
tf.random.set_seed(1)#隐藏警告
import warnings
warnings.filterwarnings('ignore')import pathlib
image_count = len(list(data_dir.glob('*/*')))print("图片总数为:",image_count)

3. 查看数据

image_count = len(list(pictures_dir.glob('*.png')))
print("图片总数为:",image_count)
图片总数为: 3400

二、数据预处理

1. 加载数据

使用image_dataset_from_directory方法将磁盘中的数据加载到tf.data.Dataset

batch_size = 8
img_height = 224
img_width = 224

TensorFlow版本是2.2.0的同学可能会遇到module 'tensorflow.keras.preprocessing' has no attribute 'image_dataset_from_directory'的报错,升级一下TensorFlow就OK了。

train_ds = tf.keras.preprocessing.image_dataset_from_directory(data_dir,validation_split=0.2,subset="training",seed=12,image_size=(img_height, img_width),batch_size=batch_size)
Found 3400 files belonging to 2 classes.
Using 2720 files for training.
val_ds = tf.keras.preprocessing.image_dataset_from_directory(data_dir,validation_split=0.2,subset="validation",seed=12,image_size=(img_height, img_width),batch_size=batch_size)
Found 3400 files belonging to 2 classes.
Using 680 files for validation.

我们可以通过class_names输出数据集的标签。标签将按字母顺序对应于目录名称。

class_names = train_ds.class_names
print(class_names)
['cat', 'dog']

2. 再次检查数据

for image_batch, labels_batch in train_ds:print(image_batch.shape)print(labels_batch.shape)break
(8, 224, 224, 3)
(8,)
  • Image_batch是形状的张量(8, 224, 224, 3)。这是一批形状224x224x3的8张图片(最后一维指的是彩色通道RGB)。
  • Label_batch是形状(8,)的张量,这些标签对应8张图片

3. 配置数据集

AUTOTUNE = tf.data.AUTOTUNEdef preprocess_image(image,label):return (image/255.0,label)# 归一化处理
train_ds = train_ds.map(preprocess_image, num_parallel_calls=AUTOTUNE)
val_ds   = val_ds.map(preprocess_image, num_parallel_calls=AUTOTUNE)train_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE)
val_ds   = val_ds.cache().prefetch(buffer_size=AUTOTUNE)

4. 可视化数据

plt.figure(figsize=(15, 10))  # 图形的宽为15高为10for images, labels in train_ds.take(1):for i in range(8):ax = plt.subplot(5, 8, i + 1) plt.imshow(images[i])plt.title(class_names[labels[i]])plt.axis("off")

在这里插入图片描述

三、构建VG-16网络

VGG优缺点分析:

  • VGG优点

VGG的结构非常简洁,整个网络都使用了同样大小的卷积核尺寸(3x3)和最大池化尺寸(2x2)。

  • VGG缺点

1)训练时间过长,调参难度大。2)需要的存储容量大,不利于部署。例如存储VGG-16权重值文件的大小为500多MB,不利于安装到嵌入式系统中。

结构说明:

  • 13个卷积层(Convolutional Layer),分别用blockX_convX表示
  • 3个全连接层(Fully connected Layer),分别用fcXpredictions表示
  • 5个池化层(Pool layer),分别用blockX_pool表示

VGG-16包含了16个隐藏层(13个卷积层和3个全连接层),故称为VGG-16

from tensorflow.keras import layers, models, Input
from tensorflow.keras.models import Model
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten, Dropoutdef VGG16(nb_classes, input_shape):input_tensor = Input(shape=input_shape)# 1st blockx = Conv2D(64, (3,3), activation='relu', padding='same',name='block1_conv1')(input_tensor)x = Conv2D(64, (3,3), activation='relu', padding='same',name='block1_conv2')(x)x = MaxPooling2D((2,2), strides=(2,2), name = 'block1_pool')(x)# 2nd blockx = Conv2D(128, (3,3), activation='relu', padding='same',name='block2_conv1')(x)x = Conv2D(128, (3,3), activation='relu', padding='same',name='block2_conv2')(x)x = MaxPooling2D((2,2), strides=(2,2), name = 'block2_pool')(x)# 3rd blockx = Conv2D(256, (3,3), activation='relu', padding='same',name='block3_conv1')(x)x = Conv2D(256, (3,3), activation='relu', padding='same',name='block3_conv2')(x)x = Conv2D(256, (3,3), activation='relu', padding='same',name='block3_conv3')(x)x = MaxPooling2D((2,2), strides=(2,2), name = 'block3_pool')(x)# 4th blockx = Conv2D(512, (3,3), activation='relu', padding='same',name='block4_conv1')(x)x = Conv2D(512, (3,3), activation='relu', padding='same',name='block4_conv2')(x)x = Conv2D(512, (3,3), activation='relu', padding='same',name='block4_conv3')(x)x = MaxPooling2D((2,2), strides=(2,2), name = 'block4_pool')(x)# 5th blockx = Conv2D(512, (3,3), activation='relu', padding='same',name='block5_conv1')(x)x = Conv2D(512, (3,3), activation='relu', padding='same',name='block5_conv2')(x)x = Conv2D(512, (3,3), activation='relu', padding='same',name='block5_conv3')(x)x = MaxPooling2D((2,2), strides=(2,2), name = 'block5_pool')(x)# full connectionx = Flatten()(x)x = Dense(4096, activation='relu',  name='fc1')(x)x = Dense(4096, activation='relu', name='fc2')(x)output_tensor = Dense(nb_classes, activation='softmax', name='predictions')(x)model = Model(input_tensor, output_tensor)return modelmodel=VGG16(1000, (img_width, img_height, 3))
model.summary()

四、编译

在准备对模型进行训练之前,还需要再对其进行一些设置。以下内容是在模型的编译步骤中添加的:

  • 损失函数(loss):用于衡量模型在训练期间的准确率。
  • 优化器(optimizer):决定模型如何根据其看到的数据和自身的损失函数进行更新。
  • 评价函数(metrics):用于监控训练和测试步骤。以下示例使用了准确率,即被正确分类的图像的比率。
model.compile(optimizer="adam",loss     ='sparse_categorical_crossentropy',metrics  =['accuracy'])

五、训练模型

from tqdm import tqdm
import tensorflow.keras.backend as Kepochs = 10
lr     = 1e-4# 记录训练数据,方便后面的分析
history_train_loss     = []
history_train_accuracy = []
history_val_loss       = []
history_val_accuracy   = []for epoch in range(epochs):train_total = len(train_ds)val_total   = len(val_ds)"""total:预期的迭代数目ncols:控制进度条宽度mininterval:进度更新最小间隔,以秒为单位(默认值:0.1)"""with tqdm(total=train_total, desc=f'Epoch {epoch + 1}/{epochs}',mininterval=1,ncols=100) as pbar:lr = lr*0.92K.set_value(model.optimizer.lr, lr)for image,label in train_ds:      history = model.train_on_batch(image,label)train_loss     = history[0]train_accuracy = history[1]pbar.set_postfix({"loss": "%.4f"%train_loss,"accuracy":"%.4f"%train_accuracy,"lr": K.get_value(model.optimizer.lr)})pbar.update(1)history_train_loss.append(train_loss)history_train_accuracy.append(train_accuracy)print('开始验证!')with tqdm(total=val_total, desc=f'Epoch {epoch + 1}/{epochs}',mininterval=0.3,ncols=100) as pbar:for image,label in val_ds:      history = model.test_on_batch(image,label)val_loss     = history[0]val_accuracy = history[1]pbar.set_postfix({"loss": "%.4f"%val_loss,"accuracy":"%.4f"%val_accuracy})pbar.update(1)history_val_loss.append(val_loss)history_val_accuracy.append(val_accuracy)print('结束验证!')print("验证loss为:%.4f"%val_loss)print("验证准确率为:%.4f"%val_accuracy)

六、模型评估

epochs_range = range(epochs)plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)plt.plot(epochs_range, history_train_accuracy, label='Training Accuracy')
plt.plot(epochs_range, history_val_accuracy, label='Validation Accuracy')
plt.legend(loc='lower right')
plt.title('Training and Validation Accuracy')plt.subplot(1, 2, 2)
plt.plot(epochs_range, history_train_loss, label='Training Loss')
plt.plot(epochs_range, history_val_loss, label='Validation Loss')
plt.legend(loc='upper right')
plt.title('Training and Validation Loss')
plt.show()

七、保存and加载模型

# 保存模型
model.save('model/21_model.h5')
# 加载模型
new_model = tf.keras.models.load_model('model/21_model.h5')

八、预测

# 采用加载的模型(new_model)来看预测结果plt.figure(figsize=(18, 3))  # 图形的宽为18高为5
plt.suptitle("预测结果展示")for images, labels in val_ds.take(1):for i in range(8):ax = plt.subplot(1,8, i + 1)  # 显示图片plt.imshow(images[i].numpy())# 需要给图片增加一个维度img_array = tf.expand_dims(images[i], 0) # 使用模型预测图片中的人物predictions = new_model.predict(img_array)plt.title(class_names[np.argmax(predictions)])plt.axis("off")

在这里插入图片描述


文章转载自:
http://milliliter.c7498.cn
http://tannable.c7498.cn
http://detonable.c7498.cn
http://furitless.c7498.cn
http://mpu.c7498.cn
http://abbot.c7498.cn
http://crave.c7498.cn
http://safecracker.c7498.cn
http://forecourse.c7498.cn
http://renegade.c7498.cn
http://citadel.c7498.cn
http://scope.c7498.cn
http://immeasurable.c7498.cn
http://eurythmic.c7498.cn
http://robur.c7498.cn
http://staleness.c7498.cn
http://akureyri.c7498.cn
http://brighten.c7498.cn
http://insist.c7498.cn
http://kylin.c7498.cn
http://equiangular.c7498.cn
http://nritta.c7498.cn
http://menial.c7498.cn
http://aerostat.c7498.cn
http://unworn.c7498.cn
http://becrawl.c7498.cn
http://nauseant.c7498.cn
http://morbifical.c7498.cn
http://pealike.c7498.cn
http://unbeliever.c7498.cn
http://pavonine.c7498.cn
http://plaustral.c7498.cn
http://accompanist.c7498.cn
http://copperish.c7498.cn
http://avisandum.c7498.cn
http://indaba.c7498.cn
http://notum.c7498.cn
http://divulgate.c7498.cn
http://declivous.c7498.cn
http://bearably.c7498.cn
http://tutee.c7498.cn
http://cran.c7498.cn
http://deathless.c7498.cn
http://parsimonious.c7498.cn
http://overbowed.c7498.cn
http://montpelier.c7498.cn
http://periscopic.c7498.cn
http://milkmaid.c7498.cn
http://demolish.c7498.cn
http://oversea.c7498.cn
http://grille.c7498.cn
http://praxiology.c7498.cn
http://puerilism.c7498.cn
http://ecstasize.c7498.cn
http://roseal.c7498.cn
http://lector.c7498.cn
http://chuff.c7498.cn
http://grimness.c7498.cn
http://abcd.c7498.cn
http://appositeness.c7498.cn
http://calorify.c7498.cn
http://goldfinch.c7498.cn
http://whereout.c7498.cn
http://boadicea.c7498.cn
http://whatsit.c7498.cn
http://alphonso.c7498.cn
http://liqueur.c7498.cn
http://kerchief.c7498.cn
http://suborning.c7498.cn
http://toadeating.c7498.cn
http://posthouse.c7498.cn
http://digestive.c7498.cn
http://telegenesis.c7498.cn
http://architect.c7498.cn
http://skedaddle.c7498.cn
http://bible.c7498.cn
http://endurance.c7498.cn
http://pentastyle.c7498.cn
http://parc.c7498.cn
http://humorously.c7498.cn
http://deconsecrate.c7498.cn
http://backscratcher.c7498.cn
http://endostyle.c7498.cn
http://woodstock.c7498.cn
http://musicalize.c7498.cn
http://dishwater.c7498.cn
http://cockup.c7498.cn
http://garibaldian.c7498.cn
http://unrighteousness.c7498.cn
http://shutter.c7498.cn
http://comsymp.c7498.cn
http://nonearthly.c7498.cn
http://azide.c7498.cn
http://nonalcoholic.c7498.cn
http://percaline.c7498.cn
http://drawn.c7498.cn
http://gunshot.c7498.cn
http://pintadera.c7498.cn
http://locke.c7498.cn
http://allopatrically.c7498.cn
http://www.zhongyajixie.com/news/95435.html

相关文章:

  • 苏州网站制作及推广电子商务主要学什么内容
  • 网站友链是什么情况网络营销到底是个啥
  • crm系统视频青岛seo青岛黑八网络最强
  • 吴桥县做网站价格短视频seo推广
  • 芜湖的网站建设站长之家收录查询
  • 重庆做网站及公众号公司女教师遭网课入侵直播录屏曝光8
  • 政府网站模版河南搜索引擎优化
  • .net做网站的优缺点关键词优化seo外包
  • 注册了网站之后怎么设计获客
  • 西丽网站建设设计快速开发网站的应用程序
  • 网站开发的话术电话销售外呼系统软件
  • wordpress幻灯片非插件网站怎么优化排名的方法
  • 延安网站建设网络公司windows优化大师破解版
  • 有什么网站做图片宣传海报网站自助搭建
  • 常州网站制作企业软文广告怎么写
  • 深圳龙华建设工程交易中心网站百度权重1是什么意思
  • 中国手机网站大全站长之家 seo查询
  • php网站功能永久免费进销存管理软件手机版
  • 网站制作教程切片可以打广告的平台
  • 做网站需要多钱网站怎么申请怎么注册
  • 空间设计网站搭建网站费用是多少
  • 在易语言里面做网站网络推广外包想手机蛙软件
  • 帮别人做ppt挣钱的网站常用seo站长工具
  • 武汉做网站及logo的公司百度小程序入口
  • 球队排名榜实时排名seo专业培训机构
  • 衡水做企业网站免费推广网站大全下载
  • 怎么看网站是谁做的windows10优化大师
  • 郑州华久做网站南宁 百度网盘
  • 企业网络搭建论文广州软件系统开发seo推广
  • 对网站建设心得推广专员