Untitled
unknown
plain_text
3 years ago
1.4 kB
9
Indexable
import glob import itertools import os.path #dir = 'D:\\USERS\\DAN\\OneDrive\\Projects\\Bc\\baltrip-dataset-one-class\\labels' dir = 'D:\\USERS\\DAN\\Downloads\\Self Driving Car.v2-fixed-large.yolov5pytorch\\export\\labels' items = glob.glob(dir + "/*.txt") no_of_items = len(items) items_done = 0 for item in items: #itertools.islice(items, 10): temp = [] items_done += 1 print('\n#######>-' + str(items_done) + '/' + str(no_of_items) + '-<#####################################################' '\n' + os.path.basename(item)) print(str(items_done) + '/' + str(no_of_items)) with open(item, "r") as f: for line in f: line_as_list = list(line) #print(line_as_list) if line_as_list[0] == str(1): #Class 1 is "car", Class 10 is "truck". So I can use just one condition #line_as_list[0] = 0 #I don't need to rename anything, because I can choose to approach the dataset as single class when training (with --single-cls) tmp_line = ''.join(map(str, line_as_list)) print(line_as_list) print(tmp_line) temp.append(tmp_line) elif line_as_list[0] != str(1): line_as_list = '' tmp_line = ''.join(map(str, line_as_list)) print('debug: ' + tmp_line) with open(item, "w") as f: f.writelines(temp)
Editor is loading...