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

网站建设维护教程私人定制平台网站

网站建设维护教程,私人定制平台网站,博客网站,网站用什么技术做本笔记记录使用自定义Layer和Model来做CIFAR10数据集的训练。 CIFAR10数据集下载#xff1a; https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz 自定义的Layer和Model实现较为简单#xff0c;参数量较少#xff0c;并且没有卷积层和dropout等#xff0c;最终准确率…       本笔记记录使用自定义Layer和Model来做CIFAR10数据集的训练。 CIFAR10数据集下载 https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz 自定义的Layer和Model实现较为简单参数量较少并且没有卷积层和dropout等最终准确率不高仅做练习使用。 import tensorflow as tf import numpy as np from tensorflow import keras from tensorflow.keras import datasets, layers, optimizers, Sequential, metricstf.__version__def preprocess(x, y):x tf.cast(x, dtypetf.float32) / 255y tf.cast(y, dtypetf.int32)return x,ybatchsize 128 #CIFAR10数据集下载可以直接使用网络下载 (x,y), (x_val, y_val) datasets.cifar10.load_data() #CIFAR10的标签训练集数据维度是[50000, 1],通过squeeze消除掉里面1的维度变成[50000] print(y.shape:, y.shape) y tf.squeeze(y) print(squeezed y.shape:, y.shape) y_val tf.squeeze(y_val) #进行onehot编码 y tf.one_hot(y, depth10) y_val tf.one_hot(y_val, depth10) print(Datasets: , x.shape, , y.shape, x.min():, x.min(), x.max():, x.max())train_db tf.data.Dataset.from_tensor_slices((x, y)) train_db train_db.map(preprocess).shuffle(10000).batch(batchsize) test_db tf.data.Dataset.from_tensor_slices((x_val, y_val)) test_db test_db.map(preprocess).batch(batchsize)sample next(iter(train_db)) print(Batch:, sample[0].shape, sample[1].shape)#自定义Layer class MyDense(layers.Layer):def __init__(self, input_dim, output_dim):super(MyDense, self).__init__()self.kernel self.add_weight(namew, shape[input_dim, output_dim], initializertf.random_uniform_initializer(0, 1.0))self.bias self.add_weight(nameb, shape[output_dim], initializertf.random_uniform_initializer(0, 1.0))#self.kernel self.add_weight(namew, shape[input_dim, output_dim])#self.bias self.add_weight(nameb, shape[output_dim])def call(self, inputs, training None):x inputsself.kernel self.biasreturn xclass MyNetwork(keras.Model):def __init__(self):super(MyNetwork, self).__init__()self.fc1 MyDense(32 * 32 * 3, 512)self.fc2 MyDense(512, 512)self.fc3 MyDense(512, 256)self.fc4 MyDense(256, 256)self.fc5 MyDense(256, 10)def call(self, inputs, training None):x tf.reshape(inputs, [-1, 32 * 32 * 3])x self.fc1(x)x tf.nn.relu(x)x self.fc2(x)x tf.nn.relu(x)x self.fc3(x)x tf.nn.relu(x)x self.fc4(x)x tf.nn.relu(x)x self.fc5(x)x tf.nn.relu(x)#返回logitsreturn xtotal_epoches 35 learn_rate 0.001 network MyNetwork() network.compile(optimizeroptimizers.Adam(learning_ratelearn_rate),loss tf.losses.CategoricalCrossentropy(from_logitsTrue),metrics[Accuracy]) network.fit(train_db, epochstotal_epoches, validation_datatest_db, validation_freq1) 运行结果
http://www.pierceye.com/news/107716/

相关文章:

  • 如何重建网站广州市服务好的网站制作排名
  • 做一名优秀网站设计师计划网站描述怎样写
  • 网页二级网站怎么做网监关闭的网站怎么恢复
  • 甘肃省建设监理协会 官方网站国内知名公关公司
  • 如何将网站和域名绑定阿里云1M做网站
  • 南城网站建设公司咨询东莞智通人才网最新招聘
  • app建设网站公司哪家好php网站修改代码
  • 哪些网上订餐的网站做的好地情网站建设
  • 重庆推广网站的方法国内最近的新闻大事
  • 网站需要备案吗网站怎么推广软文
  • 做设计开哪个素材网站的会员好手机免费网站建设哪家公司好
  • 征婚网站认识的男人做定投保做高级电工题的网站
  • 学做饼干的网站汕头建设学校的网站
  • asp.net做网站原理工资卡app下载
  • 做齐鲁油官方网站集团网站建设报价
  • 网站的收录情况怎么查企业网银怎么登录
  • 网站开发会计处理wordpress阅读随机增加
  • 兰州做网站公司哪家好公司网站建设是什么意思
  • 小区物业管理网站开发报告deal 网站要怎么做
  • seo站长助手wordpress 注册侧边栏
  • 做网站是要编程吗那些网站是html5做的
  • 网站开发图在网站做电子画册
  • 怎样建一个英文网站wordpress 多用户商城
  • 制作一个自适应网站源码app在线生成器
  • Dw做html网站项目管理软件有哪些
  • 天津网站建设定制软件开发服务公司
  • 做企业网站cms减肥网站源码
  • 建设工程检测预约网站猎头公司怎么找
  • 北京网站手机站建设公司手机网站开发常用工具
  • 太原做网站联系方式论坛的网站开发项目