摘要: 实例 import tensorflow as tf import os num_epochs = 10 batch_size = 32 learning_rate = 0.001 data_dir = 'C:/datasets/cats_vs_dogs' train_cats_dir = data 阅读全文
posted @ 2022-02-17 16:52 wuyuan2011woaini 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 简单粗暴的tensorflow-模型与层 简单粗暴的tensorflow-多层感知机(MLP) 简单粗暴的tensorflow-CNN 简单粗暴的tensorflow-RNN 简单粗暴的tensorflow-Keras Pipeline 简单粗暴的tensorflow-自定义层、损失函数、评估指标 阅读全文
posted @ 2022-02-17 16:05 wuyuan2011woaini 阅读(27) 评论(0) 推荐(0) 编辑
摘要: # tensorboard可视化参数 summary_writer = tf.summary.create_file_writer('./tensorboard') #存放 TensorBoard 的记录文件 # 开始模型训练 for batch_index in range(num_batches 阅读全文
posted @ 2022-02-17 15:33 wuyuan2011woaini 阅读(83) 评论(0) 推荐(0) 编辑
摘要: # train.py 模型训练阶段 model = MyModel() # 实例化Checkpoint,指定保存对象为model(如果需要保存Optimizer的参数也可加入) checkpoint = tf.train.Checkpoint(myModel=model) # ...(模型训练代码) 阅读全文
posted @ 2022-02-17 15:22 wuyuan2011woaini 阅读(40) 评论(0) 推荐(0) 编辑
摘要: # 自定义层 y_pred=w*x+b class LinearLayer(tf.keras.layers.Layer): def __init__(self, units): super().__init__() self.units = units def build(self, input_s 阅读全文
posted @ 2022-02-17 15:09 wuyuan2011woaini 阅读(46) 评论(0) 推荐(0) 编辑
摘要: # Keras Pipeline model = tf.keras.models.Sequential([ #模型定义 tf.keras.layers.Flatten(), tf.keras.layers.Dense(100, activation=tf.nn.relu), tf.keras.lay 阅读全文
posted @ 2022-02-17 15:01 wuyuan2011woaini 阅读(50) 评论(0) 推荐(0) 编辑
摘要: # 数据集 class DataLoader(): def __init__(self): path = tf.keras.utils.get_file('nietzsche.txt', origin='https://s3.amazonaws.com/text-datasets/nietzsche 阅读全文
posted @ 2022-02-17 14:39 wuyuan2011woaini 阅读(26) 评论(0) 推荐(0) 编辑
摘要: # CNN模型定义 class CNN(tf.keras.Model): def __init__(self): super().__init__() self.conv1 = tf.keras.layers.Conv2D( #卷积层定义 filters=32, # 卷积层神经元(卷积核)数目 ke 阅读全文
posted @ 2022-02-17 14:01 wuyuan2011woaini 阅读(36) 评论(0) 推荐(0) 编辑
摘要: # 数据集 class MNISTLoader(): def __init__(self): mnist = tf.keras.datasets.mnist (self.train_data, self.train_label), (self.test_data, self.test_label) 阅读全文
posted @ 2022-02-17 13:49 wuyuan2011woaini 阅读(102) 评论(0) 推荐(0) 编辑
摘要: #y_pred = a * X + b进行模型建立 import tensorflow as tf X = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) y = tf.constant([[10.0], [20.0]]) class Linear(t 阅读全文
posted @ 2022-02-17 13:35 wuyuan2011woaini 阅读(34) 评论(0) 推荐(0) 编辑