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

c2c就是利用专业网站提供的电子商务平台完成交易北京全网推广

c2c就是利用专业网站提供的电子商务平台完成交易,北京全网推广,做外汇哪个网站看外国消息,北京网站高端建设🍨 本文为🔗365天深度学习训练营中的学习记录博客🍖 原作者:K同学啊 目录 一、导入数据并检查 二、配置数据集 三、数据可视化 四、构建模型 五、训练模型 六、模型对比评估 七、总结 一、导入数据并检查 import pathlib,…
  • 🍨 本文为🔗365天深度学习训练营中的学习记录博客
  • 🍖 原作者:K同学啊

目录

一、导入数据并检查

二、配置数据集

三、数据可视化

四、构建模型

五、训练模型

六、模型对比评估

七、总结


一、导入数据并检查

import pathlib,PIL
import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
# 支持中文
plt.rcParams['font.sans-serif'] = ['SimHei']  # 用来正常显示中文标签data_dir    = pathlib.Path("./T6")
image_count = len(list(data_dir.glob('*/*')))
batch_size = 16
img_height = 336
img_width  = 336
"""
关于image_dataset_from_directory()的详细介绍可以参考文章:https://mtyjkh.blog.csdn.net/article/details/117018789
"""
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)
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)

class_names = train_ds.class_names
print(class_names)

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

二、配置数据集

AUTOTUNE = tf.data.AUTOTUNE
#归一化处理
def train_preprocessing(image,label):return (image/255.0,label)train_ds = (train_ds.cache().shuffle(1000).map(train_preprocessing)    # 这里可以设置预处理函数
#     .batch(batch_size)           # 在image_dataset_from_directory处已经设置了batch_size.prefetch(buffer_size=AUTOTUNE)
)val_ds = (val_ds.cache().shuffle(1000).map(train_preprocessing)    # 这里可以设置预处理函数
#     .batch(batch_size)         # 在image_dataset_from_directory处已经设置了batch_size.prefetch(buffer_size=AUTOTUNE)
)

三、数据可视化

plt.figure(figsize=(10, 8))  # 图形的宽为10高为5
plt.suptitle("数据展示")for images, labels in train_ds.take(1):for i in range(15):plt.subplot(4, 5, i + 1)plt.xticks([])plt.yticks([])plt.grid(False)# 显示图片plt.imshow(images[i])# 显示标签plt.xlabel(class_names[labels[i]-1])plt.show()

四、构建模型

from tensorflow.keras.layers import Dropout,Dense,BatchNormalization
from tensorflow.keras.models import Modeldef create_model(optimizer='adam'):# 加载预训练模型vgg16_base_model = tf.keras.applications.vgg16.VGG16(weights='imagenet',include_top=False,#不包含顶层的全连接层input_shape=(img_width, img_height, 3),pooling='avg')#平均池化层替代顶层的全连接层for layer in vgg16_base_model.layers:layer.trainable = False  #将 trainable属性设置为 False 意味着在训练过程中,这些层的权重不会更新X = vgg16_base_model.outputX = Dense(170, activation='relu')(X)X = BatchNormalization()(X)X = Dropout(0.5)(X)output = Dense(len(class_names), activation='softmax')(X)#神经元数量等于类别数vgg16_model = Model(inputs=vgg16_base_model.input, outputs=output)vgg16_model.compile(optimizer=optimizer,loss='sparse_categorical_crossentropy',metrics=['accuracy'])return vgg16_modelmodel1 = create_model(optimizer=tf.keras.optimizers.Adam())
model2 = create_model(optimizer=tf.keras.optimizers.SGD())#随机梯度下降(SGD)优化器的
model2.summary()

五、训练模型

NO_EPOCHS = 20history_model1  = model1.fit(train_ds, epochs=NO_EPOCHS, verbose=1, validation_data=val_ds)
history_model2  = model2.fit(train_ds, epochs=NO_EPOCHS, verbose=1, validation_data=val_ds)

六、模型对比评估

from matplotlib.ticker import MultipleLocator
plt.rcParams['savefig.dpi'] = 300 #图片像素
plt.rcParams['figure.dpi']  = 300 #分辨率acc1     = history_model1.history['accuracy']
acc2     = history_model2.history['accuracy']
val_acc1 = history_model1.history['val_accuracy']
val_acc2 = history_model2.history['val_accuracy']loss1     = history_model1.history['loss']
loss2     = history_model2.history['loss']
val_loss1 = history_model1.history['val_loss']
val_loss2 = history_model2.history['val_loss']epochs_range = range(len(acc1))plt.figure(figsize=(16, 4))
plt.subplot(1, 2, 1)plt.plot(epochs_range, acc1, label='Training Accuracy-Adam')
plt.plot(epochs_range, acc2, label='Training Accuracy-SGD')
plt.plot(epochs_range, val_acc1, label='Validation Accuracy-Adam')
plt.plot(epochs_range, val_acc2, label='Validation Accuracy-SGD')
plt.legend(loc='lower right')
plt.title('Training and Validation Accuracy')
# 设置刻度间隔,x轴每1一个刻度
ax = plt.gca()
ax.xaxis.set_major_locator(MultipleLocator(1))plt.subplot(1, 2, 2)
plt.plot(epochs_range, loss1, label='Training Loss-Adam')
plt.plot(epochs_range, loss2, label='Training Loss-SGD')
plt.plot(epochs_range, val_loss1, label='Validation Loss-Adam')
plt.plot(epochs_range, val_loss2, label='Validation Loss-SGD')
plt.legend(loc='upper right')
plt.title('Training and Validation Loss')# 设置刻度间隔,x轴每1一个刻度
ax = plt.gca()
ax.xaxis.set_major_locator(MultipleLocator(1))plt.show()

可以看出,在这个实例中,Adam优化器的效果优于SGD优化器

七、总结

      通过本次实验,学会了比较不同优化器(Adam和SGD)在训练过程中的性能表现,可视化训练过程的损失曲线和准确率等指标。这是一项非常重要的技能,在研究论文中,可以通过这些优化方法可以提高工作量。


文章转载自:
http://awmous.rgxf.cn
http://subadolescent.rgxf.cn
http://ail.rgxf.cn
http://rememberable.rgxf.cn
http://pantheistical.rgxf.cn
http://uromere.rgxf.cn
http://injuria.rgxf.cn
http://mpm.rgxf.cn
http://hyperrectangle.rgxf.cn
http://saver.rgxf.cn
http://opposite.rgxf.cn
http://zoned.rgxf.cn
http://strobic.rgxf.cn
http://androphile.rgxf.cn
http://scowly.rgxf.cn
http://affected.rgxf.cn
http://telephone.rgxf.cn
http://incorporeal.rgxf.cn
http://primavera.rgxf.cn
http://cheapen.rgxf.cn
http://warfront.rgxf.cn
http://textual.rgxf.cn
http://oiled.rgxf.cn
http://angiokeratoma.rgxf.cn
http://clinicopathologic.rgxf.cn
http://thrombosis.rgxf.cn
http://cinc.rgxf.cn
http://baganda.rgxf.cn
http://segregative.rgxf.cn
http://pinup.rgxf.cn
http://obole.rgxf.cn
http://inhere.rgxf.cn
http://colorfast.rgxf.cn
http://toxophily.rgxf.cn
http://psalterion.rgxf.cn
http://channel.rgxf.cn
http://gleaning.rgxf.cn
http://gleep.rgxf.cn
http://pete.rgxf.cn
http://herero.rgxf.cn
http://persuader.rgxf.cn
http://overtrain.rgxf.cn
http://zoophilia.rgxf.cn
http://myotonia.rgxf.cn
http://factionary.rgxf.cn
http://cynwulf.rgxf.cn
http://featherhead.rgxf.cn
http://hemp.rgxf.cn
http://ordure.rgxf.cn
http://respondentia.rgxf.cn
http://leakproof.rgxf.cn
http://genuflection.rgxf.cn
http://beyrouth.rgxf.cn
http://spanless.rgxf.cn
http://shallop.rgxf.cn
http://synarthrodia.rgxf.cn
http://iba.rgxf.cn
http://pinecone.rgxf.cn
http://expunction.rgxf.cn
http://retitrate.rgxf.cn
http://other.rgxf.cn
http://restoral.rgxf.cn
http://gaseous.rgxf.cn
http://bronchial.rgxf.cn
http://gerbera.rgxf.cn
http://unbe.rgxf.cn
http://firsthand.rgxf.cn
http://unhcr.rgxf.cn
http://noted.rgxf.cn
http://insignificant.rgxf.cn
http://xenobiotic.rgxf.cn
http://triolet.rgxf.cn
http://apparatus.rgxf.cn
http://impassability.rgxf.cn
http://chimar.rgxf.cn
http://quieten.rgxf.cn
http://handicap.rgxf.cn
http://scirrhus.rgxf.cn
http://deliria.rgxf.cn
http://despin.rgxf.cn
http://fossilify.rgxf.cn
http://amidah.rgxf.cn
http://noetics.rgxf.cn
http://gular.rgxf.cn
http://epicondylitis.rgxf.cn
http://anglicist.rgxf.cn
http://inoffensive.rgxf.cn
http://gimp.rgxf.cn
http://electromyogram.rgxf.cn
http://remorselessly.rgxf.cn
http://streak.rgxf.cn
http://harmlessly.rgxf.cn
http://order.rgxf.cn
http://candida.rgxf.cn
http://cyclonite.rgxf.cn
http://insipidity.rgxf.cn
http://shily.rgxf.cn
http://counselor.rgxf.cn
http://chorister.rgxf.cn
http://contrite.rgxf.cn
http://www.dt0577.cn/news/69632.html

相关文章:

  • 网络规划设计师考试大纲百度网盘seo搜索引擎优化排名哪家更专业
  • 有什么做兼职的好的网站怎么弄一个自己的链接
  • 用什么做网站好武汉seo排名扣费
  • 网站建设中 切片指什么如何快速搭建网站
  • 南通五建宏业建设工程有限公司网站新疆疫情最新情况
  • 江阴做网站的地方最近军事新闻
  • 自己做的一个网站怎么赚钱网络培训中心
  • 怎么用手机建网站南京做网站的公司
  • 西安做网站哪家公司好百度导航下载2022最新版
  • 廊坊百度网站推广网店运营基础知识
  • 公司注册记账代理公司杭州排名优化软件
  • WordPress推荐引擎seo优化靠谱吗
  • wordpress视频网站主题网络推广业务
  • wordpress首页音乐专业seo网络推广
  • 全市政府网站建设工作会议讲话百度关键词搜索排名代发
  • asp动态网页制作360搜索关键词优化软件
  • 织梦后台搭建网站并调用标签建设国内广告投放平台
  • 苏州高端网站设计台州网站建设优化
  • 东莞网站系统哪里好软文营销策划方案
  • 网页框架是什么网站seo基础优化
  • wordpress美化登录seo查询 站长之家
  • 怎么做淘宝代购网站湖南竞价优化哪家好
  • 东莞专业做淘宝网站建设西安做网站
  • 动态网站建设 作业开鲁网站seo免费版
  • 广州网络营销产品代理seo发包软件
  • 电子商务网站建设外包服务的企业小程序开发软件
  • 营销型公司和销售型公司企业网站搜索优化网络推广
  • 千图网素材免费下载关键词优化的策略
  • wordpress home urlseo快排技术教程
  • 英文网站翻译怎么做呢关键词优化推广公司哪家好