![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Tensorflow
sunyuan123
这个作者很懒,什么都没留下…
展开
-
循环神经网络:用RNN训练数据集IMDB得到语句与偏好的关系
import tensorflow as tfimport numpy as npfrom tensorflow import kerasfrom tensorflow.keras import datasets, layers, optimizers, Sequential, metricsfrom tensorflow.keras.preprocessing import sequencetf.random.set_seed(114514)np.random.seed(114514)#原创 2020-12-09 21:37:50 · 273 阅读 · 0 评论 -
Resnet训练CIFAR100数据集
resnet.py,用来构造一个18或34层的残差神经网络:import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import layers, Sequentialclass BasicBlock(layers.Layer): def __init__(self, filter_num, stride=1): super(BasicBlock, self).__init__() self.co原创 2020-12-06 17:55:46 · 3429 阅读 · 1 评论 -
Bug解决
之前提到过出现了一个诡异的错误,今天终于解决了。源程序中有一行 train_db = train_db.map(preprocess), 把这行删掉然后在之前预处理下x,y就好了。原因似乎是调用train_db = train_db.map(preprocess)后tensorflow会把train_db当成一个tf.Variable类型,而这类变量很容易出bug (?)无bug代码import tensorflow as tffrom tensorflow import kerasfrom ten原创 2020-12-06 12:03:58 · 195 阅读 · 1 评论 -
利用卷积神经网络实验数据集CIFAR100
代码:import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import datasets, layers, optimizers, Sequential, metricstf.random.set_seed(1234)(x_train,y_train), (x_test,y_test) = datasets.cifar100.load_data()y_train = tf.squeeze(y_tr原创 2020-12-05 19:53:06 · 637 阅读 · 0 评论 -
一个诡异的错误
今天实验了如下代码:import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import datasets, layers, optimizers, Sequential, metricsdef preprocess(x, y): x = 2*tf.cast(x,dtype=tf.float32)/255.0-1.0 y = tf.cast(y,dtype=tf.int32) return x,y原创 2020-12-05 07:12:03 · 119 阅读 · 0 评论 -
Tensorboard初体验
Tensorboard是Tensorflow自带的可视化工具,功能非常强大。首先运行如下代码:import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import datasets, layers, optimizers, Sequential, metricsimport tensorboardimport datetimemnist = tf.keras.datasets.mnist(x_tra原创 2020-12-04 15:51:37 · 141 阅读 · 1 评论 -
多层神经网络
数据集为fashion_mnist,功能为识别衣服类型。准确度稳定在90%左右,且当训练次数加大时,明显出现了过拟合现象。import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import datasets, layers, optimizers, Sequential, metricsdef preprocess(x, y): x = tf.cast(x,dtype=tf.float32)/255.0原创 2020-12-04 12:16:08 · 266 阅读 · 1 评论 -
第一个神经网络
import tensorflow as tffrom tensorflow import kerasfrom tensorflow.keras import datasetsimport osos.environ['TF_CPP_MIN_LOG_LEVEL']='2'(x,y),_ = datasets.mnist.load_data()x = tf.convert_to_tensor(x,dtype=tf.float32)/255.0y = tf.convert_to_tensor(原创 2020-12-01 11:17:43 · 215 阅读 · 0 评论 -
张量与第一个计算图
张量与第一个计算图Tensorflow里面,基本的数据单元是张量,即多维数组。数据与数据之间用有向边连接,构成了计算图来看如下代码:import tensorflow.compat.v1 as tftf.disable_v2_behavior()a=tf.constant([1.0,2.0])b=tf.constant([3.0,4.0])c=a+bprint(c)输出结果如下Tensor("add:0", shape=(2,), dtype=float32)这个输出结果记录了节点原创 2020-11-29 13:26:43 · 149 阅读 · 0 评论 -
Python回顾
Python复习笔记基本操作sum = 0for x in range(101): sum = sum + xprint(sum)sum = 0n = 99while n > 0: sum = sum + n n = n - 2print(sum)L = ['Bart', 'Lisa', 'Adam']for x in L: print('Hello',x)函数def my_abs(x): if x >= 0: r原创 2020-11-29 10:10:45 · 87 阅读 · 0 评论 -
Tensorflow初次安装
Tensorflow初次安装基本配置具体步骤基本配置Windows 10Anaconda 3Python 3.9Tensorflow GPU versionGTX1060具体步骤安装 Anaconda 3的Windows版本。打开Anaconda Powershell, 在命令行中使用以下命令创建 conda 环境:conda create -n tensorflow python=3.9可能会有不明原因导致多次重启。(我重启了三次= =)安装完毕后输入如下命令,进入Tensorf原创 2020-11-28 22:22:56 · 144 阅读 · 0 评论