国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

對(duì)tensorflow中cifar-10文檔的Read操作詳解

2020-02-15 21:18:25
字體:
供稿:網(wǎng)友

前言

在tensorflow的官方文檔中得卷積神經(jīng)網(wǎng)絡(luò)一章,有一個(gè)使用cifar-10圖片數(shù)據(jù)集的實(shí)驗(yàn),搭建卷積神經(jīng)網(wǎng)絡(luò)倒不難,但是那個(gè)cifar10_input文件著實(shí)讓我費(fèi)了一番心思。配合著官方文檔也算看的七七八八,但是中間還是有一些不太明白,不明白的mark一下,這次記下一些已經(jīng)明白的。

研究

cifar10_input.py文件的read操作,主要的就是下面的代碼:

if not eval_data:  filenames = [os.path.join(data_dir, 'data_batch_%d.bin' % i)         for i in xrange(1, 6)]  num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN else:  filenames = [os.path.join(data_dir, 'test_batch.bin')]  num_examples_per_epoch = NUM_EXAMPLES_PER_EPOCH_FOR_EVAL...filename_queue = tf.train.string_input_producer(filenames)...label_bytes = 1 # 2 for CIFAR-100 result.height = 32 result.width = 32 result.depth = 3 image_bytes = result.height * result.width * result.depth # Every record consists of a label followed by the image, with a # fixed number of bytes for each. record_bytes = label_bytes + image_bytes # Read a record, getting filenames from the filename_queue. No # header or footer in the CIFAR-10 format, so we leave header_bytes # and footer_bytes at their default of 0. reader = tf.FixedLengthRecordReader(record_bytes=record_bytes) result.key, value = reader.read(filename_queue) ... if shuffle:  images, label_batch = tf.train.shuffle_batch(    [image, label],    batch_size=batch_size,    num_threads=num_preprocess_threads,    capacity=min_queue_examples + 3 * batch_size,    min_after_dequeue=min_queue_examples) else:  images, label_batch = tf.train.batch(    [image, label],    batch_size=batch_size,    num_threads=num_preprocess_threads,    capacity=min_queue_examples + 3 * batch_size)

開始并不明白這段代碼是用來干什么的,越看越糊涂,因?yàn)橹笆褂胻ensorflow最多也就是使用哪個(gè)tf.placeholder()這個(gè)操作,并沒有使用tensorflow自帶的讀寫方法來讀寫,所以上面的代碼看的很費(fèi)勁兒。不過我在官方文檔的How-To這個(gè)document中看到了這個(gè)東西:

Batchingdef read_my_file_format(filename_queue): reader = tf.SomeReader() key, record_string = reader.read(filename_queue) example, label = tf.some_decoder(record_string) processed_example = some_processing(example) return processed_example, labeldef input_pipeline(filenames, batch_size, num_epochs=None): filename_queue = tf.train.string_input_producer(   filenames, num_epochs=num_epochs, shuffle=True) example, label = read_my_file_format(filename_queue) # min_after_dequeue defines how big a buffer we will randomly sample #  from -- bigger means better shuffling but slower start up and more #  memory used. # capacity must be larger than min_after_dequeue and the amount larger #  determines the maximum we will prefetch. Recommendation: #  min_after_dequeue + (num_threads + a small safety margin) * batch_size min_after_dequeue = 10000 capacity = min_after_dequeue + 3 * batch_size example_batch, label_batch = tf.train.shuffle_batch(   [example, label], batch_size=batch_size, capacity=capacity,   min_after_dequeue=min_after_dequeue) return example_batch, label_batch            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 防城港市| 巫溪县| 中阳县| 桃源县| 聂荣县| 天柱县| 白水县| 安龙县| 洞头县| 津市市| 合水县| 江源县| 安庆市| 鄢陵县| 台东市| 康平县| 德化县| 嘉善县| 涿州市| 河北省| 台南市| 汽车| 砚山县| 祁东县| 启东市| 昌江| 湘乡市| 堆龙德庆县| 旬阳县| 仙桃市| 塔河县| 攀枝花市| 荥阳市| 石嘴山市| 张家界市| 浪卡子县| 江永县| 溧水县| 绥中县| 定边县| 陆川县|