Parsing txt file
# -*- coding: utf-8 -*-
__author__ = "Pingjun Chen"
__email__ = "chenpingjun@gmx.com"
import os, sys, pdb
def organize_images(txt_path, image_path):
with open(txt_path) as f:
content = f.readlines()
for ele in content:
ele = ele.strip('\n')
desp = ele.split("\t")
category = desp[1]
filename = desp[0]
file_dir = os.path.join(image_path, category)
if not os.path.exists(file_dir):
os.mkdir(file_dir)
src_file_path = os.path.join(image_path, filename)
dst_file_path = os.path.join(file_dir, filename)
os.rename(src_file_path, dst_file_path)
if __name__ == "__main__":
txt_path = "./val_annotations.txt"
image_path = "./images"
organize_images(txt_path, image_path)