Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.vscode/
.idea/

.DS_Store
*.py[cod]

model/
*.result/
File renamed without changes
File renamed without changes
48 changes: 37 additions & 11 deletions inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import logging
log = logging.getLogger(__name__)

import model
# import model
import model as model_tx
import time

import os
import argparse
import random

class Detector(object):
Expand Down Expand Up @@ -66,22 +68,40 @@ def iou_count(list1, list2):
iou = inter / min(area1, area2)
return iou

if __name__ == '__main__':

result_path = './result/'
instance = Detector('./model/')
images = os.listdir('./image/')
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument('--model_dir', default='./model')
parser.add_argument('--img_dir', default='./tx_infer_data')
parser.add_argument('--out_dir', default='./result')
return parser.parse_args()


row_root = './tx_infer_data/row'
col_root = './tx_infer_data/col'
nrow_root = './tx_infer_data/nrow'
ncol_root = './tx_infer_data/ncol'
def main(args):
# result_path = './result/'
if not os.path.isdir(args.out_dir):
os.makedirs(args.out_dir)
os.makedirs(os.path.join(args.out_dir, 'row'))
os.makedirs(os.path.join(args.out_dir, 'col'))
os.makedirs(os.path.join(args.out_dir, 'nrow'))
os.makedirs(os.path.join(args.out_dir, 'ncol'))

instance = Detector(args.model_dir)
images = os.listdir(args.img_dir)

# row_root = './tx_infer_data/row'
# col_root = './tx_infer_data/col'
# nrow_root = './tx_infer_data/nrow'
# ncol_root = './tx_infer_data/ncol'
row_root = os.path.join(args.out_dir, 'row')
col_root = os.path.join(args.out_dir, 'col')
nrow_root = os.path.join(args.out_dir, 'nrow')
ncol_root = os.path.join(args.out_dir, 'ncol')

i_l = []
for x in range(len(images)):
print(images[x])
image_path = os.path.join('./image/',images[x])
image_path = os.path.join(args.img_dir, images[x])
image_name = images[x]
txt_name = image_name.replace('.jpg','.txt')
row_path = os.path.join(row_root, image_name)
Expand Down Expand Up @@ -111,7 +131,7 @@ def iou_count(list1, list2):
lmap = cv2.bitwise_and(score_row, score_col)
pre_map = cv2.bitwise_and(nmap, lmap)

result = os.path.join(result_path, images[x])
result = os.path.join(args.out_dir, images[x])
score_nrow_map = cv2.resize(score_nrow, dsize=None, fx=1/ratio_w, fy=1/ratio_h, interpolation=cv2.INTER_AREA)
score_ncol_map = cv2.resize(score_ncol, dsize=None, fx=1 / ratio_w, fy=1 / ratio_h, interpolation=cv2.INTER_AREA)
score_row_map = cv2.resize(score_row, dsize=None, fx=1 / ratio_w, fy=1 / ratio_h, interpolation=cv2.INTER_AREA)
Expand All @@ -124,3 +144,9 @@ def iou_count(list1, list2):
cv2.imwrite(nrow_path, score_nrow_map * 255)
cv2.imwrite(ncol_path, score_ncol_map * 255)
cv2.imwrite(result, pre_map*255)


if __name__ == '__main__':
main(get_args())


2 changes: 0 additions & 2 deletions model/checkpoint

This file was deleted.

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ plumbum==1.6.2
numpy==1.12.1
ipython==6.1.0
Pillow==4.2.1
opencv-python
tensorflow==1.15