当前位置: 首页 > 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.zqtcl.cn/news/107716/

相关文章:

  • 胶州哪家公司做网站wordpress的html
  • 辽宁省建设厅网站江苏住房和城乡建设厅官方网站
  • 链接关系 网站层次结构南宁做网站找哪家公司
  • 定制网站开发哪家好崇明建设镇网站
  • 上海网站制作建设是什么wordpress管理页面
  • 酒店网站设计的目的和意义网络营销相关理论
  • 用google翻译做多语言网站企业官网建站网站
  • 南阳网站建设培训学校莞城短视频seo优化
  • 开发商城网站建设做网站租用那个服务器好
  • 2015做导航网站wordpress中文主
  • 中英文网站建设报价河南网站建设推广公司
  • 什么是建设网站提升seo排名平台
  • 广告设计模板网站模版网站是什么意思
  • 网站网站模板企业网站制作排名
  • 食品网站开发淘客手机版网站怎么做
  • 厦门市网站建设app开发水务 网站建设
  • jfinal网站开发装修公司加盟哪家最好
  • 成都个人网站制作石家庄设计网站公司
  • 阿里巴巴网站本土化建设烟台市两学一做网站
  • 潍坊品牌网站建设公司旅游类作业网站
  • 建设谷歌公司网站费用求职seo推荐
  • 企业网站建设规划ppt企业网站前端模板下载
  • 补习吧 一家专门做家教的网站百度云搜索引擎入口网盘搜索神器
  • 网站建设与制作企业嘉鱼网站建设哪家专业
  • 电脑怎么做网站赚钱柳州柳北建设局网站
  • 农村服务建设有限公司网站设计基础网站推荐
  • 做网站的编程语言组合ppt模板免费的网站推荐
  • 泰安企业建站公司流程上海营销型网站报价
  • 网站承载量怎么做福州公交集团网站建设
  • 新吴区住房和建设交通局网站小程序商城哪家好排行榜