栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Tensorflow(二十九) —— 卷积神经网络(CNN)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Tensorflow(二十九) —— 卷积神经网络(CNN)

Tensorflow(二十九) —— 卷积神经网络(CNN)
  • 1. layers.BatchNormalization
  • 2. 实战

1. layers.BatchNormalization
import tensorflow as tf
from tensorflow.keras import layers,optimizers
import matplotlib.pyplot as plt
# ************************ layers.BatchNormalization
x = tf.random.normal([784,10],mean = 1,stddev=0.5)
net = layers.BatchNormalization(axis = -1,
                               center = True,
                               scale = True,
                               trainable = True)
net(x,training = False).shape
2. 实战
x = tf.random.normal([2,3])
net = layers.BatchNormalization()

out = net(x)
print(out.shape)

print(net.trainable_variables)
print(net.variables)

x = tf.random.normal([2,4,4,3],mean = 1,stddev=0.5)
net = layers.BatchNormalization(axis = -1)

out = net(x,training = False)
print(net.variables)

out1 = net(x,training = True)
print(net.variables)

for i in range(100):
    net(x,training = True)
print(net.variables)

# backward update
optimizer = optimizers.Adam(lr = 1e-3)
for i in range(10):
    with tf.GradientTape() as tape:
        out = net(x,training = True)
        loss = tf.reduce_mean(out**2)
    grads = tape.gradient(loss,net.trainable_variables)
    optimizer.apply_gradients(zip(grads,net.trainable_variables))

print(net.trainable_variables)

本文为参考龙龙老师的“深度学习与TensorFlow 2入门实战“课程书写的学习笔记

by CyrusMay 2022 04 18

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/822838.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号