import numpy as np import tensorflow as tf import matplotlib.pyplot as plt #读取图片 image_raw_data = tf.gfile.FastGFile("F:\\TensorFlowGoogle\\201806-github\\datasets\\cat.jpg",'rb').read() with tf.Session() as sess: img_data = tf.image.decode_jpeg…
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt # 定义RNN的参数. HIDDEN_SIZE = 30 # LSTM中隐藏节点的个数. NUM_LAYERS = 2 # LSTM的层数. TIMESTEPS = 10 # 循环神经网络的训练序列长度. TRAINING_STEPS = 10000 # 训练轮数. BATCH_SIZE = 32 # batch大小. TRAINING_EXAMP…
import tempfile import tensorflow as tf # 1. 列举输入文件. # 输入数据生成的训练和测试数据. train_files = tf.train.match_filenames_once("F:\\output.tfrecords") test_files = tf.train.match_filenames_once("F:\\output_test.tfrecords") # 定义解析TFRecord文件的parser方…
import tempfile import tensorflow as tf # 1. 从数组创建数据集. input_data = [1, 2, 3, 5, 8] dataset = tf.data.Dataset.from_tensor_slices(input_data) # 定义迭代器. iterator = dataset.make_one_shot_iterator() # get_next() 返回代表一个输入数据的张量. x = iterator.get_next() y =…
import tensorflow as tf # 1. 创建文件列表,通过文件列表创建输入文件队列 files = tf.train.match_filenames_once("F:\\output.tfrecords") filename_queue = tf.train.string_input_producer(files, shuffle=False) #解析TFRecord文件里的数据. # 读取文件. reader = tf.TFRecordReader() _,seri…
import tensorflow as tf # 1. 生成文件存储样例数据. def _int64_feature(value): return tf.train.Feature(int64_list=tf.train.Int64List(value=[value])) num_shards = 2 instances_per_shard = 2 for i in range(num_shards): filename = ('E:\\data.tfrecords-%.5d-of-%.5d'…
import tensorflow as tf #1. 定义队列及其操作. queue = tf.FIFOQueue(100,"float") enqueue_op = queue.enqueue([tf.random_normal([1])]) qr = tf.train.QueueRunner(queue, [enqueue_op] * 5) tf.train.add_queue_runner(qr) out_tensor = queue.dequeue() #2. 启动线程. w…