tf.gfile.fastgfile(『path』, 『rb』).read()
讀取結果是最原始的影象,沒有經過解碼。如果要顯示讀入的影象,則需要解碼,tf.image.decode_jepg和tf.image.decode_png分別用於解碼jpg格式和png格式的影象,得到影象的畫素值,這個畫素值可以用於顯示影象。
plt.show()decode輸出是tensor,eval後是ndarray
讀取檔案名字然後獲取影象資訊
將影象檔名及標籤放入佇列中
input_queue=tf.train.slice_input_producer([image,label]) label = input_queue[1]
讀取的全部資訊
image_contents = tf.read_file(input_queue[0])
把解碼,channels =3 為彩色, r,g ,b 黑白為 1 ,也可以理解為的厚度
image=tf.image.decode_jpeg(image_contents,channels =3)
#tensor形式
#將以中心進行裁剪或者擴充為指定的尺寸image_w,image_h
image=tf.image.resize_image_with_crop_or_pad(image, image_w, image_h)
#對資料進行標準化,標準化,就是減去它的均值除以方差
image = tf.image.per_image_standardization(image)
生成批次 num_threads 有多少個執行緒根據電腦配置設定 capacity 佇列中最多容納的個數
tf.train.shuffle_batch 打亂順序,
image_batch, label_batch = tf.train.batch([image, label],batch_size = batch_size, num_threads = 64, capacity = capacity)
重新定義下 label_batch 的形狀
label_batch = tf.reshape(label_batch , [batch_size])
轉化
image_batch = tf.cast(image_batch,tf.float32)
C 檔案操作 提取 處理檔案中資料
在a.txt 檔案中格式為 名字 工資 將 工資提取出來,進行 4操作 再放到檔案中。string strlines file.readalllines d viang desktop a.txt encoding.default 讀取檔案的每一行 for int i 0 i strlines.le...
txt檔案中按日期提取資料
old.txt 2695350881 20190204 00250990da50 2553358 714165 0 0 0 0 1549323678 0 n 0 0 0 提取表頭 head n 1 old.txt new.txt按日期提取 可指定多少行,可指定多個日期 檢視某個日期記錄的行數 gre...
python提取txt檔案中的資料
從儲存在txt檔案中的30000多條資料當中提取自己需要的資訊,如下圖示例的資料格式,需要提取出now後的數值並儲存在另外乙個txt檔案當中。結果示例 r as f 開啟檔案 data f.read 讀取檔案 path w r c now 1.txt with open path w,w as f ...