在自己电脑上生成txt文件保存的是本机的路径,但是需要放到服务器上训练,此时就需要修改txt文件中的路径为服务器上的路径,用以下代码即可解决。
change_dir.py
import os
txt_path1 = 'train_all.txt'
txt_path2 = 'train_all_2.txt'
txt_new = []
f1 = open(txt_path1, 'r',encoding='utf-8')
for line in f1:
img_name = line.split('/')[-1]
line_new = './images/train2017/'+ img_name
txt_new.append(line_new)
f1.close()
f2 = open(txt_path2, 'w', encoding='utf-8')
for line in txt_new:
f2.writelines(line)
f2.close()