This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Team-BoonMoSa/dev
Ver 1.0
- Loading branch information
Showing
3 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
|
||
|
||
def checkData(target): | ||
os.chdir(init + '/FlickrLogos-v2') | ||
try: | ||
os.chdir('images/' + target) | ||
except: | ||
print('경로가 없어용 ~') | ||
|
||
imgDir = os.getcwd() | ||
img = os.listdir() | ||
|
||
labDir = imgDir.replace('images', 'labels') | ||
lab = os.listdir() | ||
|
||
tmpi = [] | ||
for i in img: | ||
tmpi.append(i[:-4]) | ||
|
||
tmpj = [] | ||
for i in lab: | ||
tmpj.append(i[:-4]) | ||
|
||
for i in tmpi: | ||
if not i in tmpj and not 'ipynb' in i: | ||
print('NG: ', i) | ||
|
||
for i in tmpj: | ||
if not i in tmpi and not 'ipynb' in i: | ||
print('NG: ', i) | ||
|
||
print('='*20, target, '='*20) | ||
print('Images: ', len(img)) | ||
print('Ground Truth: ', len(lab)) | ||
print('='*20, target, '='*20) | ||
|
||
if __name__ == "__main__": | ||
os.chdir('..') | ||
init = os.getcwd() | ||
try: | ||
os.chdir(init + '/FlickrLogos-v2') | ||
except: | ||
print('경로가 없어용 ~') | ||
|
||
checkData('train') | ||
checkData('val') | ||
checkData('test') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import os | ||
import shutil | ||
|
||
import csv | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from tqdm import tqdm | ||
import cv2 | ||
|
||
|
||
def initializeData(): | ||
tmp = os.getcwd() | ||
try: | ||
os.chdir('FlickrLogos-v2') | ||
except Exception as e: | ||
print('There is no FlickrLogos-v2') | ||
print(e) | ||
os.chdir(tmp) | ||
return | ||
try: | ||
shutil.rmtree('images') | ||
except: | ||
pass | ||
try: | ||
shutil.rmtree('labels') | ||
except: | ||
pass | ||
os.mkdir('images') | ||
os.chdir('images') | ||
os.mkdir('train') | ||
os.mkdir('val') | ||
os.mkdir('test') | ||
os.chdir('..') | ||
os.mkdir('labels') | ||
os.chdir('labels') | ||
os.mkdir('train') | ||
os.mkdir('val') | ||
os.mkdir('test') | ||
os.chdir(tmp) | ||
|
||
|
||
def saveData(target, brand, img): | ||
targetDirImg = datasets + '/FlickrLogos-v2/images/' + target | ||
targetDirLab = datasets + '/FlickrLogos-v2/labels/' + target | ||
absDataDir = datasets + '/FlickrLogos-v2' | ||
# Make Target Data: IMG | ||
absImgDir = absDataDir + '/classes/jpg/' + brand + '/' + img | ||
shutil.copy(absImgDir, targetDirImg + '/' + img) | ||
# Make Target Data: Bbox (GT) | ||
absBboxDir = absDataDir + '/classes/masks/' + brand.lower() + '/' + img + '.bboxes.txt' | ||
mh, mw, _ = cv2.imread(absImgDir).shape | ||
bbox = pd.read_csv(absBboxDir, sep=' ') | ||
with open(targetDirLab + '/' + img[:-4] + '.txt', 'a', encoding='utf-8') as f: | ||
wr = csv.writer(f, delimiter=' ') | ||
for i in range(len(bbox)): | ||
x, y, width, height = bbox.iloc[i] | ||
wr.writerow([0, x / mw, y / mh, width / mw, height / mh]) | ||
|
||
if __name__ == "__main__": | ||
os.chdir('..') | ||
initializeData() | ||
|
||
datasets = os.getcwd() | ||
|
||
os.chdir(datasets + '/FlickrLogos-v2/classes/jpg') | ||
brands = os.listdir() | ||
|
||
cnt = 0 | ||
for brand in tqdm(brands): | ||
if not '.' in brand and not brand == 'no-logo': | ||
os.chdir(datasets + '/FlickrLogos-v2/classes/jpg/' + brand) | ||
for img in os.listdir(): | ||
if '.jpg' in img: | ||
if cnt % 12 == 0: | ||
saveData('val', brand, img) | ||
elif cnt % 12 == 1: | ||
saveData('test', brand, img) | ||
else: | ||
saveData('train', brand, img) | ||
cnt += 1 | ||
|
||
print('=' * 30) | ||
print('No. Total Data: ', cnt) | ||
print('=' * 30) | ||
|
||
os.chdir(datasets + '/FlickrLogos-v2/images/train') | ||
tin = len(os.listdir()) | ||
print('Training Data: No. Images', tin) | ||
|
||
os.chdir(datasets + '/FlickrLogos-v2/labels/train') | ||
ttn = len(os.listdir()) | ||
print('Training Data: No. GT', ttn) | ||
|
||
os.chdir(datasets + '/FlickrLogos-v2/images/val') | ||
vin = len(os.listdir()) | ||
print('Validation Data: No. Images', vin) | ||
|
||
os.chdir(datasets + '/FlickrLogos-v2/labels/val') | ||
vtn = len(os.listdir()) | ||
print('Validation Data: No. GT', vtn) | ||
|
||
os.chdir(datasets + '/FlickrLogos-v2/images/test') | ||
ttin = len(os.listdir()) | ||
print('Test Data: No. Images', ttin) | ||
|
||
os.chdir(datasets + '/FlickrLogos-v2/labels/test') | ||
tttn = len(os.listdir()) | ||
print('Test Data: No. GT', tttn) | ||
|
||
print('=' * 30) | ||
print('No. Total Image Data: ', tin + vin + ttin) | ||
print('No. Total GT Data: ', ttn + vtn + tttn) | ||
print('=' * 30) | ||
|
||
os.chdir(datasets + '/MakeData') |