日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

TensorFlow TFRecord

發(fā)布時(shí)間:2024/2/28 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TensorFlow TFRecord 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

把mnist數(shù)據(jù)集另存為T(mén)FRecord格式

import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import numpy as npdef _int64_feature(value):return tf.train.Feature(int64_list=tf.train.Int64List(value=[value]))def _bytes_feature(value):return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))mnist = input_data.read_data_sets("MNIST_data/", dtype=tf.uint8, one_hot=True)images = mnist.train.images print(images.shape) pixels = images.shape[1] #圖像分辯率28*28=784 labels = mnist.train.labelsfilename = "MNIST_data/output.tfrecords" writer = tf.python_io.TFRecordWriter(filename)num = mnist.train.num_examples print(num) for i in range(num):example = tf.train.Example(features=tf.train.Features(feature={'pixels':_int64_feature(pixels),'label':_int64_feature(np.argmax(labels[i])),'image_raw':_bytes_feature(images[i].tostring())}))writer.write(example.SerializeToString()) writer.close()
讀TFRecord格式

import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data import numpy as np#隊(duì)列 queue = tf.train.string_input_producer(["MNIST_data/output.tfrecords"])reader = tf.TFRecordReader() _, serialized_example = reader.read(queue)#解析數(shù)據(jù),對(duì)應(yīng)寫(xiě)入格式 features = tf.parse_single_example(serialized_example,features={'image_raw':tf.FixedLenFeature([], tf.string),'pixels':tf.FixedLenFeature([], tf.int64),'label':tf.FixedLenFeature([], tf.int64)} )images = tf.decode_raw(features['image_raw'], tf.uint8) labels = tf.cast(features['label'], tf.int32) pixels = tf.cast(features['pixels'], tf.int32)with tf.Session() as sess:coord = tf.train.Coordinator()#啟動(dòng)多線程輸入數(shù)據(jù)threads = tf.train.start_queue_runners(sess=sess, coord=coord)for i in range(2):image, label, pixel = sess.run([images, labels, pixels])print(label)print(image.shape)print(pixel)

總結(jié)

以上是生活随笔為你收集整理的TensorFlow TFRecord的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。