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

秦皇岛哪家做网站好杭州百度快照优化公司

秦皇岛哪家做网站好,杭州百度快照优化公司,产品开发外包,布吉网站建设哪家公司靠谱🍨 本文为🔗365天深度学习训练营中的学习记录博客 🍖 原作者:K同学啊 VGG 网络优缺点分析: ● 优点: 结构简洁统一:整张网络结构统一,只使用 33 的小卷积核和 22 的最大池化&…
  •    🍨 本文为🔗365天深度学习训练营中的学习记录博客
  •    🍖 原作者:K同学啊

VGG 网络优缺点分析:

● 优点:

  • 结构简洁统一:整张网络结构统一,只使用 3×3 的小卷积核和 2×2 的最大池化,便于理解和实现。

  • 效果稳定可靠:在多个图像识别任务中表现优异,是深度学习初学者和工业部署常用的经典网络结构之一。

● 缺点:

  1. 参数量大:VGG-16 拥有超过 1 亿个参数,模型体积大(权重文件约 500MB),不适合嵌入式或移动端部署。

  2. 训练耗时长:由于网络较深,训练时间较长,且对计算资源要求较高。

  3. 调参难度高:没有采用跳连接结构,深层网络可能会遇到梯度消失问题,调参过程较为复杂。

一.前期工作

1.设置GPU

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")

2.导入数据 

 

from tensorflow       import keras
from tensorflow.keras import layers,models
import numpy             as np
import matplotlib.pyplot as plt
import os,PIL,pathlibdata_dir = "../data/end_data"
data_dir = pathlib.Path(data_dir)

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

二.数据预处理

1.加载数据

batch_size = 8
img_height = 224
img_width = 224

train_ds = tf.keras.preprocessing.image_dataset_from_directory(data_dir,validation_split=0.2,subset="training",seed=123,image_size=(img_height, img_width),batch_size=batch_size)

val_ds = tf.keras.preprocessing.image_dataset_from_directory(data_dir,validation_split=0.2,subset="validation",seed=123,image_size=(img_height, img_width),batch_size=batch_size)

class_names = train_ds.class_names
print(class_names)

2.可视化数据

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

for image_batch, labels_batch in train_ds:print(image_batch.shape)print(labels_batch.shape)break

3.配置数据集

AUTOTUNE = tf.data.AUTOTUNEtrain_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE)
val_ds   = val_ds.cache().prefetch(buffer_size=AUTOTUNE)

normalization_layer = layers.experimental.preprocessing.Rescaling(1./255)train_ds = train_ds.map(lambda x, y: (normalization_layer(x), y))
val_ds   = val_ds.map(lambda x, y: (normalization_layer(x), y))

三.构建VGG-16网络

1.自建模型

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(len(class_names), (img_width, img_height, 3))
model.summary()

四.编译

# 设置初始学习率
initial_learning_rate = 1e-4lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay(initial_learning_rate,decay_steps=30,      # 敲黑板!!!这里是指 steps,不是指epochsdecay_rate=0.92,     # lr经过一次衰减就会变成 decay_rate*lrstaircase=True)# 设置优化器
opt = tf.keras.optimizers.Adam(learning_rate=initial_learning_rate)model.compile(optimizer=opt,loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),metrics=['accuracy'])

五.训练模型

epochs = 10history = model.fit(train_ds,validation_data=val_ds,epochs=epochs
)

六.可视化结果

from datetime import datetime
current_time = datetime.now() # 获取当前时间acc = history.history['accuracy']
val_acc = history.history['val_accuracy']loss = history.history['loss']
val_loss = history.history['val_loss']epochs_range = range(epochs)plt.figure(figsize=(12, 4))
plt.subplot(1, 2, 1)
plt.plot(epochs_range, acc, label='Training Accuracy')
plt.plot(epochs_range, val_acc, label='Validation Accuracy')
plt.legend(loc='lower right')
plt.title('Training and Validation Accuracy')
plt.xlabel(current_time) # 打卡请带上时间戳,否则代码截图无效plt.subplot(1, 2, 2)
plt.plot(epochs_range, loss, label='Training Loss')
plt.plot(epochs_range, val_loss, label='Validation Loss')
plt.legend(loc='upper right')
plt.title('Training and Validation Loss')
plt.show()

http://www.cadmedia.cn/news/6264.html

相关文章:

  • 商会网站建设怎么做网络推广
  • 苏州苏网建设工程有限公司榆林市网站seo
  • wordpress 百度联盟如何软件网站优化公司
  • 广州做网站建设哪家公司好石家庄seo管理
  • 有哪些建设网站公司吗seo搜索是什么
  • 网站建设费属哪个费用网站优化推广价格
  • 合肥网站建设套餐福州seo代理计费
  • 二手房网站建设及推广方案seo公司优化排名
  • 建设政府网站的作用qq群排名优化软件
  • 谷歌ads东莞seo技术
  • 滨州做网站建设价格西宁网站seo
  • 电子商务网站模版seo三人行论坛
  • 音乐网站建设方案线上营销活动案例
  • 株洲专业网站建设品牌seo站群优化
  • 专业独立门户网站建设百度关键词分析
  • 政府网站建设先进个人培训心得体会1000字通用
  • wordpress做手机网站安卓优化大师hd
  • 网页美工实训总结海淀区seo多少钱
  • 精品国内网站建设seo网站排名全选
  • 刷单网站搭建制作网站建设入门
  • 凯里网站建设公司河南网站优化公司哪家好
  • 施工建设集团网站湖南seo技术培训
  • 沧州市科一网站下载百度2024最新版
  • 网站建设优化论坛站长工具seo优化
  • 深圳官方网站新闻北京百度竞价托管公司
  • 首饰盒东莞网站建设短视频培训学校
  • 赣州市建设工程造价管理网站sem营销推广
  • c2c网站建设需求分析百度快速排名软件下载
  • 免费的网站app下载建站系统推荐
  • 涿州网站建设qianhu微建站