python:讀取文字檔案的行資料,檔案.splitlines()
阿新 • • 發佈:2019-02-15
一般跟蹤訓練的ground_truth的資料儲存在文字文檔案中,故每一行的資料為一張圖片的標籤資料,這個時候讀取每一張圖片的標籤,具體實現如下:
test_txt = '/home/zcm/tensorf/siamfc-tf-master/data/Biker/groundtruth.txt'
def load_label_set(label_dir):
label_folder = open(label_dir, "r")
trainlines = label_folder.read().splitlines() #返回每一行的資料
for line in trainlines:
line = line.split(" " ) #按照空格鍵分割每一行裡面的資料
box = [float(line[0]), float(line[1]), float(line[2]), float(line[3])]#box讀取標籤ground_truth
label_folder.close()
return train_box
#train_box = load_train_test_set(test_txt)