在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/人工智能  Python/ 如何用浮點數(shù)數(shù)據(jù)制作tfrecords?

如何用浮點數(shù)數(shù)據(jù)制作tfrecords?

求助各位大神:
在制作tfrecords的時候,如果是整數(shù)數(shù)據(jù)或者字符串數(shù)據(jù),裝進去讀出來都沒問題,網(wǎng)上很多的例子都是拿圖片的路徑(字符串數(shù)據(jù))做教程的。
但如果是浮點數(shù)數(shù)據(jù),下方案例中,那從tfrecords讀出來的一個tensor的size則放大了一倍,從3000變成了6000(以下方代碼為例)。
這是為什么?有沒有什么方案解決?
這不是說我要作死一定要先標準化一下才寫入tfrecords而不是之后再tf.標準化,而是我的數(shù)據(jù)本身來自MySQL,就是浮點數(shù)數(shù)據(jù).....

#導入庫
import numpy as np
import tensorflow as tf


#生成數(shù)據(jù)
data= np.arange(3000).reshape((500,6))  #都是整數(shù)數(shù)據(jù)
data=(data-np.mean(data))/np.std(data)  #標準化后變成浮點數(shù)數(shù)據(jù)
data=data.tobytes()
label=1



#將數(shù)據(jù)寫入tfrecords
writer= tf.python_io.TFRecordWriter("test.tfrecords") 
example = tf.train.Example(features=tf.train.Features(
    feature={'label': tf.train.Feature(int64_list=tf.train.Int64List(value=[label])),
              'data': tf.train.Feature(bytes_list=tf.train.BytesList(value=[data]))}))
writer.write(example.SerializeToString())
writer.close()




#從tfrecords中讀取數(shù)據(jù)
filename_queue = tf.train.string_input_producer(["test.tfrecords"])
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
data_features = tf.parse_single_example(
    serialized_example,
    features={'label': tf.FixedLenFeature([], tf.int64),
               'data': tf.FixedLenFeature([], tf.string)})
data = tf.decode_raw(data_features['data'], tf.float32)
data = tf.reshape(data, [500,6])
label = tf.cast(data_features['label'], tf.int32)



#查看、打印數(shù)據(jù)
with tf.Session()  as sess:
    i = 0
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    try:
        while not coord.should_stop() and i<1:
            # just plot one batch size            
            data, label = sess.run([data, label])
            print(data, label)
            i+=1
    except tf.errors.OutOfRangeError:  
        print('done!')
    finally:
        coord.request_stop()
    coord.join(threads)
回答
編輯回答
空痕

是float64轉(zhuǎn)float32時出了問題

2018年5月7日 07:59