Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from Team-BoonMoSa/dev
Browse files Browse the repository at this point in the history
Ver 1.0
  • Loading branch information
Zerohertz authored Mar 23, 2023
2 parents 6c488c5 + 5843be5 commit ba49c77
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,54 @@ Parent

# How to use?

### saveData.py

```shell
Paraent/datasets/MakeData$ python saveData.py
100%|████████████████████████████████████████████████████████████████| 33/33 [00:26<00:00, 1.27it/s]
==============================
No. Total Data: 2240
==============================
Training Data: No. Images 1866
Training Data: No. GT 1866
Validation Data: No. Images 187
Validation Data: No. GT 187
Test Data: No. Images 187
Test Data: No. GT 187
==============================
No. Total Image Data: 2240
No. Total GT Data: 2240
==============================
```

> Result
```shell
FlickrLogos-v2
├── images
│ ├── test
│ ├── train
│ └── val
└── labels
├── test
├── train
└── val
```

### checkData.py

```shell
Paraent/datasets/MakeData$ python checkData.py
==================== train ====================
Images: 1866
Ground Truth: 1866
==================== train ====================
==================== val ====================
Images: 187
Ground Truth: 187
==================== val ====================
==================== test ====================
Images: 187
Ground Truth: 187
==================== test ====================
```
48 changes: 48 additions & 0 deletions checkData.py
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')
116 changes: 116 additions & 0 deletions saveData.py
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')

0 comments on commit ba49c77

Please sign in to comment.