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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

tensorflow-读写数据最佳代码组合方式

發布時間:2025/3/12 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 tensorflow-读写数据最佳代码组合方式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最佳組合代碼模式為:

# Create the graph, etc. init_op = tf.global_variables_initializer()# Create a session for running operations in the Graph. sess = tf.Session()# Initialize the variables (like the epoch counter). sess.run(init_op)# Start input enqueue threads. coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(sess=sess, coord=coord)try:while not coord.should_stop():# Run training steps or whateversess.run(train_op)except tf.errors.OutOfRangeError:print('Done training -- epoch limit reached') finally:# When done, ask the threads to stop.coord.request_stop()# Wait for threads to finish. coord.join(threads) sess.close()#!/usr/bin/env python2 # -*- coding: utf-8 -*- """讀取文件 """ import tensorflow as tf import osg=tf.Graph() with g.as_default():#生成文件名隊列fileName=os.getcwd()+"/1.csv"print fileNamefileNameQueue=tf.train.string_input_producer([fileName])#生成記錄鍵值對reader=tf.TextLineReader(skip_header_lines=1)key,value=reader.read(fileNameQueue)recordDefaults=[[""],[1],[1]]decoded=tf.decode_csv(value,record_defaults=recordDefaults)name,age,source=tf.train.shuffle_batch(decoded,batch_size=2,capacity=2,min_after_dequeue=1) features=tf.transpose(tf.stack([age,source]))with tf.Session(graph=g) as sess:# 開始產生文件名隊列coord = tf.train.Coordinator()threads = tf.train.start_queue_runners(coord=coord)print sess.run(features)coord.request_stop()coord.join(threads)

[[32 99]
[36 75]]

#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Sat Sep 15 10:54:53 2018讀取文件 """ import tensorflow as tf import osg=tf.Graph() with g.as_default():#生成文件名隊列fileName=os.getcwd()+"/1.csv"fileNameQueue=tf.train.string_input_producer([fileName])#生成記錄鍵值對reader=tf.TextLineReader(skip_header_lines=1)key,value=reader.read(fileNameQueue)recordDefaults=[[""],[1],[1]]decoded=tf.decode_csv(value,record_defaults=recordDefaults)name,age,source=tf.train.shuffle_batch(decoded,batch_size=2,capacity=2,min_after_dequeue=1) features=tf.stack([age,source])#此處不轉置with tf.Session(graph=g) as sess:# 開始產生文件名隊列coord = tf.train.Coordinator()threads = tf.train.start_queue_runners(coord=coord)print sess.run(features)print sess.run(key)#文件名print sess.run(value)#讀取一行的內容coord.request_stop()coord.join(threads)

[[32 36]
[99 75]]
/Users/xxxxx/Documents/AIstudy/tf/1.csv:3
lisi,36,75
$ cat 1.csv

name,age,source

zhanghua,32,99

liuzhi,29,69

lisi,36,75

總結

以上是生活随笔為你收集整理的tensorflow-读写数据最佳代码组合方式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。