轉,讀csv生成tf record格式

2021-08-21 01:34:55 字數 2922 閱讀 7881

import timeit

#檢視執行開始到結束所用的時間

import tensorflow

as tf

import os

defgenerate_tfrecords

(input_filename, output_filename):

print(

"\nstart to convert {} to {}\n".format(input_filename, output_filename))

start_time = timeit.default_timer()

writer = tf.python_io.tfrecordwriter(output_filename)

for line

in open(input_filename,

"r"):

data = line.split(

",")

label = float(data[

9])features = [float(i)

for i

in data[:

9]]

#特徵不要最後一列資料

#將資料轉化為原生 bytes

example = tf.train.example(features=tf.train.features(feature=))

writer.write(example.serializetostring())

#序列化為字串

writer.close()

print(

"successfully convert {} to {}".format(input_filename,

output_filename))

end_time = timeit.default_timer()

print(

"\nthe pretraining process ran for minutes\n".format((end_time - start_time) /

60))

defmain

():

current_path =

"g:/spyder/csv_tfrecords/"

for filename

in os.listdir(current_path):

if filename ==

"siteb.udp_train_unsupervised.csv":

#當前路徑下,需要轉換的csv檔案

generate_tfrecords(current_path+filename, current_path+filename +

".tfrecords")

return current_path+filename +

".tfrecords"

if __name__ ==

"__main__":

import timeit

#檢視執行開始到結束所用的時間

import tensorflow

as tf

import os

defgenerate_tfrecords

(input_filename, output_filename):

print(

"\nstart to convert {} to {}\n".format(input_filename, output_filename))

start_time = timeit.default_timer()

writer = tf.python_io.tfrecordwriter(output_filename)

for line

in open(input_filename,

"r"):

data = line.split(

",")

label = float(data[

9])features = [float(i)

for i

in data[:

9]]

#特徵不要最後一列資料

#將資料轉化為原生 bytes

example = tf.train.example(features=tf.train.features(feature=))

writer.write(example.serializetostring())

#序列化為字串

writer.close()

print(

"successfully convert {} to {}".format(input_filename,

output_filename))

end_time = timeit.default_timer()

print(

"\nthe pretraining process ran for minutes\n".format((end_time - start_time) /

60))

defmain

():

current_path =

"g:/spyder/csv_tfrecords/"

for filename

in os.listdir(current_path):

if filename ==

"siteb.udp_train_unsupervised.csv":

#當前路徑下,需要轉換的csv檔案

generate_tfrecords(current_path+filename, current_path+filename +

".tfrecords")

return current_path+filename +

".tfrecords"

if __name__ ==

"__main__":

php 生成csv檔案

廢話不多說,上乾貨 方法一 匯出excel csv data 匯出資料 headlist 第一行,列名 filename 輸出excel檔名 functioncsv export data array headlist array filename 將資料通過fputcsv寫到檔案控制代碼 fput...

Java生成CSV檔案

pm要求在資料庫查出資料在瀏覽器匯出為csv的檔案,一接手沒多想直接用poi存進hssfworkbook物件,最後把檔案字尾名弄csv用流直接輸出到客戶端,三下五除二就搞定了,並且能用正常開啟。後來測試發現根本不是那麼回事。其實,csv是逗號分隔的 b 純文字 b 而xls是二進位制的,顯然這種低階...

sqlplus 生成csv 檔案

set echo off 非表示 set linesize 1000 列數 set pagesize 0 不分頁 set trimspool on spool 行末 無効 set pause off 相當於自動回車 set termout off 出力 畫面表示 set feedback off 行...