Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
projects:plate [2022/05/13 20:12] – old revision restored (2022/02/07 06:01) 216.244.66.228 | projects:plate [2022/06/20 14:19] (current) – old revision restored (2022/03/12 21:34) 154.54.249.201 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
+ | |||
+ | < | ||
+ | git clone https:// | ||
+ | </ | ||
+ | |||
+ | <file python convert.py> | ||
+ | import os | ||
+ | from os import walk, getcwd | ||
+ | from PIL import Image | ||
+ | |||
+ | classes = [" | ||
+ | |||
+ | def convert(size, | ||
+ | dw = 1./ | ||
+ | dh = 1./ | ||
+ | x = (box[0] + box[1])/ | ||
+ | y = (box[2] + box[3])/ | ||
+ | w = box[1] - box[0] | ||
+ | h = box[3] - box[2] | ||
+ | x = x*dw | ||
+ | w = w*dw | ||
+ | y = y*dh | ||
+ | h = h*dh | ||
+ | return (x,y,w,h) | ||
+ | |||
+ | |||
+ | """ | ||
+ | |||
+ | """ | ||
+ | mypath = " | ||
+ | outpath = " | ||
+ | |||
+ | |||
+ | cls = " | ||
+ | |||
+ | |||
+ | wd = getcwd() | ||
+ | list_file = open(' | ||
+ | |||
+ | """ | ||
+ | txt_name_list = [] | ||
+ | for (dirpath, dirnames, filenames) in walk(mypath): | ||
+ | print(filenames) | ||
+ | txt_name_list.extend(filenames) | ||
+ | break | ||
+ | print(txt_name_list) | ||
+ | |||
+ | """ | ||
+ | for txt_name in txt_name_list: | ||
+ | # txt_file = open(" | ||
+ | |||
+ | """ | ||
+ | txt_path = mypath + txt_name | ||
+ | print(" | ||
+ | txt_file = open(txt_path, | ||
+ | lines = txt_file.read().split(' | ||
+ | |||
+ | """ | ||
+ | txt_outpath = outpath + txt_name | ||
+ | print(" | ||
+ | txt_outfile = open(txt_outpath, | ||
+ | |||
+ | |||
+ | """ | ||
+ | ct = 0 | ||
+ | for line in lines: | ||
+ | # | ||
+ | # | ||
+ | # | ||
+ | if(len(line) >= 2): | ||
+ | ct = ct + 1 | ||
+ | print(line + " | ||
+ | elems = line.split(' | ||
+ | print(elems) | ||
+ | cls_id = elems[0].split(' | ||
+ | xmin = elems[0].split(' | ||
+ | xmax = elems[2] | ||
+ | ymin = elems[1] | ||
+ | ymax = elems[3][: | ||
+ | # | ||
+ | img_path = str(' | ||
+ | #t = magic.from_file(img_path) | ||
+ | #wh= re.search(' | ||
+ | im=Image.open(img_path) | ||
+ | w= int(im.size[0]) | ||
+ | h= int(im.size[1]) | ||
+ | #w = int(xmax) - int(xmin) | ||
+ | #h = int(ymax) - int(ymin) | ||
+ | # print(xmin) | ||
+ | print(w, h) | ||
+ | b = (float(xmin), | ||
+ | bb = convert((w, | ||
+ | print(bb) | ||
+ | txt_outfile.write(str(cls_id) + " " + " " | ||
+ | |||
+ | """ | ||
+ | if(ct != 0): | ||
+ | list_file.write(' | ||
+ | |||
+ | list_file.close() | ||
+ | </ | ||
+ | |||
+ | |||
+ | Train.txt Text.txt | ||
+ | |||
+ | |||
+ | <file python process.py> | ||
+ | import glob, os | ||
+ | |||
+ | # Current directory | ||
+ | current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
+ | |||
+ | # Directory where the data will reside, relative to ' | ||
+ | path_data = ' | ||
+ | |||
+ | # Percentage of images to be used for the test set | ||
+ | percentage_test = 10; | ||
+ | |||
+ | # Create and/or truncate train.txt and test.txt | ||
+ | file_train = open(' | ||
+ | file_test = open(' | ||
+ | |||
+ | # Populate train.txt and test.txt | ||
+ | counter = 1 | ||
+ | index_test = round(100 / percentage_test) | ||
+ | for pathAndFilename in glob.iglob(os.path.join(current_dir, | ||
+ | title, ext = os.path.splitext(os.path.basename(pathAndFilename)) | ||
+ | |||
+ | if counter == index_test: | ||
+ | counter = 1 | ||
+ | file_test.write(path_data + title + ' | ||
+ | else: | ||
+ | file_train.write(path_data + title + ' | ||
+ | counter = counter + 1 | ||
+ | </ | ||
+ | |||
+ | Put images inside BBox-Label-Tool/ | ||
+ | convert to JPEG and delete old images | ||
+ | < | ||
+ | mogrify -format JPEG *.jpg | ||
+ | rm *.jpg | ||
+ | </ | ||
+ | |||
+ | Go to main folder and run python main.py | ||
+ | < | ||
+ | python main.py | ||
+ | </ | ||
+ | |||
+ | Write 001 inside Image Dir box and load | ||
+ | |||
+ | Create a label for each image | ||
+ | |||
+ | After that, exit and create a new directory inside Label | ||
+ | < | ||
+ | mkdir output | ||
+ | </ | ||
+ | Run convert.py | ||
+ | < | ||
+ | python convert.py | ||
+ | </ | ||
+ | |||
+ | Now create test.txt and train.txt with process.py | ||
+ | < | ||
+ | python process.py | ||
+ | </ | ||
+ | < | ||
+ | ├── Images (input) | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | ├── Labels (output) | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | </ | ||
+ | ====== Darknet ====== | ||
+ | < | ||
+ | git clone https:// | ||
+ | cd darknet | ||
+ | make | ||
+ | </ | ||
+ | |||
+ | Copy train.txt and test.txt inside darknet/ | ||
+ | |||
+ | Create 3 files: | ||
+ | obj.data | ||
+ | obj.names | ||
+ | obj.cfg | ||
+ | |||
+ | <file obj.data> | ||
+ | classes= *NUMBER CLASSES* | ||
+ | train = *TRAIN DIRECTORY+ | ||
+ | valid = *TEST DIRECTORY* | ||
+ | names = obj.names | ||
+ | backup = *BACKUP FOLDER* | ||
+ | </ | ||
+ | |||
+ | <file obj.names> | ||
+ | *CLASS NAME* | ||
+ | </ | ||
+ | |||
+ | Copy yolov2-tiny.cfg and change [region]: | ||
+ | classes = *NUMBER CLASSES* | ||
+ | filters = (*NUMBER CLASSES* +5)*5 | ||
+ | |||
- | * https:// | ||
- | * https:// |