-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathchange_label.py
107 lines (73 loc) · 1.91 KB
/
change_label.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import shutil
from pathlib import Path
from PIL import Image
from pyzbar import pyzbar
from datetime import datetime
import argparse
import time
import subprocess
import signal
import numpy as np
import re
import math
import serial
from scipy.ndimage import filters
import base64
import cv2
import io
import sys
global name
name = "t_image"
global path
path = name + "/"
global search1
search1 = name + "_for all dataset"
global dir_weights
dir_weights = 'yolov4.weights'
global dir_cfg
dir_cfg = 'cfg/yolov4.cfg'
global dir_coco
dir_coco = 'cfg/coco.names'
global name_file
name_file = 'cfg/classes.txt'
if os.path.exists(search1):
print("already has file")
shutil.rmtree(search1)
os.makedirs(search1)
else:
os.makedirs(search1)
print("찾을 label의 번호를 입력하시오")
o1 = int(input())
print("몇 번으로 바꾸시겠습니까?(번호입력)")
n1 = int(input())
file_list = os.listdir(path)
file_list_py = [file for file in file_list if file.endswith(".txt")]
search_num = 0
print ("file_list: {}".format(file_list_py))
for test1 in file_list_py:
with open(path + test1) as file:
if True:
wr1 = open(search1 + "/" + test1, 'w+')
for line in file.readlines():
label_line = line.split(" ")
if str(label_line[0]) == str(o1):
search_num += 1
label_dir = path + test1
wr1_sen = line
wr1_sen = wr1_sen.replace(str(o1),str(n1),1)
wr1.write(wr1_sen)
#print(wr1_sen)
else:
wr1.write(line)
#print("find label " + str(search_num) + "\n")
try:
shutil.copy(label_dir[0:len(label_dir) -4] + ".jpg", search1)
except:
try:
shutil.copy(label_dir[0:len(label_dir) -4] + ".jpeg", search1)
except:
shutil.copy(label_dir[0:len(label_dir) -4] + ".png", search1)
#except:
#print("error in " + test1 + "\n")
#continue