| @@ -3,9 +3,9 @@ import time | |||||
| import numpy as np | import numpy as np | ||||
| import torch | import torch | ||||
| from torch.autograd.variable import Variable | from torch.autograd.variable import Variable | ||||
| from models import PNet,RNet,ONet | |||||
| import utils as utils | |||||
| import image_tools | |||||
| from dface.core.models import PNet,RNet,ONet | |||||
| import dface.core.utils as utils | |||||
| import dface.core.image_tools as image_tools | |||||
| def create_mtcnn_net(p_model_path=None, r_model_path=None, o_model_path=None, use_cuda=True): | def create_mtcnn_net(p_model_path=None, r_model_path=None, o_model_path=None, use_cuda=True): | ||||
| @@ -256,6 +256,7 @@ class InceptionResnetV2(nn.Module): | |||||
| self.conv2d_7b = BasicConv2d(2080, 1536, kernel_size=1, stride=1) | self.conv2d_7b = BasicConv2d(2080, 1536, kernel_size=1, stride=1) | ||||
| self.avgpool_1a = nn.AvgPool2d(8, count_include_pad=False) | self.avgpool_1a = nn.AvgPool2d(8, count_include_pad=False) | ||||
| self.classif = nn.Linear(1536, num_classes) | self.classif = nn.Linear(1536, num_classes) | ||||
| self.dropout = nn.Dropout(p=0.8) | |||||
| def forward(self, x): | def forward(self, x): | ||||
| x = self.conv2d_1a(x) | x = self.conv2d_1a(x) | ||||
| @@ -275,5 +276,6 @@ class InceptionResnetV2(nn.Module): | |||||
| x = self.conv2d_7b(x) | x = self.conv2d_7b(x) | ||||
| x = self.avgpool_1a(x) | x = self.avgpool_1a(x) | ||||
| x = x.view(x.size(0), -1) | x = x.view(x.size(0), -1) | ||||
| x = self.dropout(x) | |||||
| x = self.classif(x) | x = self.classif(x) | ||||
| return x | return x | ||||
| @@ -1,5 +1,5 @@ | |||||
| import os | import os | ||||
| import config | |||||
| import dface.config as config | |||||
| import assemble as assemble | import assemble as assemble | ||||
| @@ -1,5 +1,5 @@ | |||||
| import os | import os | ||||
| import config | |||||
| import dface.config as config | |||||
| import assemble as assemble | import assemble as assemble | ||||
| @@ -1,5 +1,5 @@ | |||||
| import os | import os | ||||
| import config | |||||
| import dface.config as config | |||||
| import assemble as assemble | import assemble as assemble | ||||
| @@ -2,15 +2,15 @@ import argparse | |||||
| import cv2 | import cv2 | ||||
| import numpy as np | import numpy as np | ||||
| from core.detect import MtcnnDetector,create_mtcnn_net | |||||
| from core.imagedb import ImageDB | |||||
| from core.image_reader import TestImageLoader | |||||
| from dface.core.detect import MtcnnDetector,create_mtcnn_net | |||||
| from dface.core.imagedb import ImageDB | |||||
| from dface.core.image_reader import TestImageLoader | |||||
| import time | import time | ||||
| import os | import os | ||||
| import cPickle | import cPickle | ||||
| from core.utils import convert_to_square,IoU | |||||
| import config | |||||
| import core.vision as vision | |||||
| from dface.core.utils import convert_to_square,IoU | |||||
| import dface.config | |||||
| import dface.core.vision as vision | |||||
| def gen_onet_data(data_dir, anno_file, pnet_model_file, rnet_model_file, prefix_path='', use_cuda=True, vis=False): | def gen_onet_data(data_dir, anno_file, pnet_model_file, rnet_model_file, prefix_path='', use_cuda=True, vis=False): | ||||
| @@ -3,10 +3,8 @@ import numpy as np | |||||
| import cv2 | import cv2 | ||||
| import os | import os | ||||
| import numpy.random as npr | import numpy.random as npr | ||||
| from core.utils import IoU | |||||
| import config | |||||
| from dface.core.utils import IoU | |||||
| import dface.config as config | |||||
| def gen_pnet_data(data_dir,anno_file): | def gen_pnet_data(data_dir,anno_file): | ||||
| @@ -3,15 +3,15 @@ import argparse | |||||
| import cv2 | import cv2 | ||||
| import numpy as np | import numpy as np | ||||
| from core.detect import MtcnnDetector,create_mtcnn_net | |||||
| from core.imagedb import ImageDB | |||||
| from core.image_reader import TestImageLoader | |||||
| from dface.core.detect import MtcnnDetector,create_mtcnn_net | |||||
| from dface.core.imagedb import ImageDB | |||||
| from dface.core.image_reader import TestImageLoader | |||||
| import time | import time | ||||
| import os | import os | ||||
| import cPickle | import cPickle | ||||
| from core.utils import convert_to_square,IoU | |||||
| import config | |||||
| import core.vision as vision | |||||
| from dface.core.utils import convert_to_square,IoU | |||||
| import dface.config as config | |||||
| import dface.core.vision as vision | |||||
| def gen_rnet_data(data_dir, anno_file, pnet_model_file, prefix_path='', use_cuda=True, vis=False): | def gen_rnet_data(data_dir, anno_file, pnet_model_file, prefix_path='', use_cuda=True, vis=False): | ||||
| @@ -5,8 +5,8 @@ import numpy as np | |||||
| import sys | import sys | ||||
| import numpy.random as npr | import numpy.random as npr | ||||
| import argparse | import argparse | ||||
| import config | |||||
| import core.utils as utils | |||||
| import dface.config as config | |||||
| import dface.core.utils as utils | |||||
| def gen_data(anno_file, data_dir, prefix): | def gen_data(anno_file, data_dir, prefix): | ||||
| @@ -6,8 +6,8 @@ import random | |||||
| import sys | import sys | ||||
| import numpy.random as npr | import numpy.random as npr | ||||
| import argparse | import argparse | ||||
| import config | |||||
| import core.utils as utils | |||||
| import dface.config as config | |||||
| import dface.core.utils as utils | |||||
| @@ -6,8 +6,8 @@ import random | |||||
| import sys | import sys | ||||
| import numpy.random as npr | import numpy.random as npr | ||||
| import argparse | import argparse | ||||
| import config | |||||
| import core.utils as utils | |||||
| import dface.config as config | |||||
| import dface.core.utils as utils | |||||
| def gen_data(anno_file, data_dir, prefix): | def gen_data(anno_file, data_dir, prefix): | ||||
| @@ -2,15 +2,15 @@ import argparse | |||||
| import cv2 | import cv2 | ||||
| import numpy as np | import numpy as np | ||||
| from core.detect import MtcnnDetector,create_mtcnn_net | |||||
| from core.imagedb import ImageDB | |||||
| from core.image_reader import TestImageLoader | |||||
| from dface.core.detect import MtcnnDetector,create_mtcnn_net | |||||
| from dface.core.imagedb import ImageDB | |||||
| from dface.core.image_reader import TestImageLoader | |||||
| import time | import time | ||||
| import os | import os | ||||
| import cPickle | import cPickle | ||||
| from core.utils import convert_to_square,IoU | |||||
| import config | |||||
| import core.vision as vision | |||||
| from dface.core.utils import convert_to_square,IoU | |||||
| import dface.config as config | |||||
| import dface.core.vision as vision | |||||
| def gen_landmark48_data(data_dir, anno_file, pnet_model_file, rnet_model_file, prefix_path='', use_cuda=True, vis=False): | def gen_landmark48_data(data_dir, anno_file, pnet_model_file, rnet_model_file, prefix_path='', use_cuda=True, vis=False): | ||||
| @@ -1,46 +1,46 @@ | |||||
| from wider_loader import WIDER | |||||
| import cv2 | |||||
| import time | |||||
| #wider face original images path | |||||
| path_to_image = '/idata/data/wider_face/WIDER_train/images' | |||||
| #matlab file path | |||||
| file_to_label = './wider_face_train.mat' | |||||
| #target file path | |||||
| target_file = './anno.txt' | |||||
| wider = WIDER(file_to_label, path_to_image) | |||||
| line_count = 0 | |||||
| box_count = 0 | |||||
| print 'start transforming....' | |||||
| t = time.time() | |||||
| with open(target_file, 'w+') as f: | |||||
| # press ctrl-C to stop the process | |||||
| for data in wider.next(): | |||||
| line = [] | |||||
| line.append(str(data.image_name)) | |||||
| line_count += 1 | |||||
| for i,box in enumerate(data.bboxes): | |||||
| box_count += 1 | |||||
| for j,bvalue in enumerate(box): | |||||
| line.append(str(bvalue)) | |||||
| line.append('\n') | |||||
| line_str = ' '.join(line) | |||||
| f.write(line_str) | |||||
| st = time.time()-t | |||||
| print 'end transforming' | |||||
| print 'spend time:%ld'%st | |||||
| print 'total line(images):%d'%line_count | |||||
| print 'total boxes(faces):%d'%box_count | |||||
| from wider_loader import WIDER | |||||
| import cv2 | |||||
| import time | |||||
| #wider face original images path | |||||
| path_to_image = '/idata/data/wider_face/WIDER_train/images' | |||||
| #matlab file path | |||||
| file_to_label = './wider_face_train.mat' | |||||
| #target file path | |||||
| target_file = './anno.txt' | |||||
| wider = WIDER(file_to_label, path_to_image) | |||||
| line_count = 0 | |||||
| box_count = 0 | |||||
| print 'start transforming....' | |||||
| t = time.time() | |||||
| with open(target_file, 'w+') as f: | |||||
| # press ctrl-C to stop the process | |||||
| for data in wider.next(): | |||||
| line = [] | |||||
| line.append(str(data.image_name)) | |||||
| line_count += 1 | |||||
| for i,box in enumerate(data.bboxes): | |||||
| box_count += 1 | |||||
| for j,bvalue in enumerate(box): | |||||
| line.append(str(bvalue)) | |||||
| line.append('\n') | |||||
| line_str = ' '.join(line) | |||||
| f.write(line_str) | |||||
| st = time.time()-t | |||||
| print 'end transforming' | |||||
| print 'spend time:%ld'%st | |||||
| print 'total line(images):%d'%line_count | |||||
| print 'total boxes(faces):%d'%box_count | |||||
| @@ -1,42 +1,42 @@ | |||||
| import h5py | |||||
| import os | |||||
| class DATA(object): | |||||
| def __init__(self, image_name, bboxes): | |||||
| self.image_name = image_name | |||||
| self.bboxes = bboxes | |||||
| class WIDER(object): | |||||
| def __init__(self, file_to_label, path_to_image): | |||||
| self.file_to_label = file_to_label | |||||
| self.path_to_image = path_to_image | |||||
| self.f = h5py.File(file_to_label, 'r') | |||||
| self.event_list = self.f.get('event_list') | |||||
| self.file_list = self.f.get('file_list') | |||||
| self.face_bbx_list = self.f.get('face_bbx_list') | |||||
| def next(self): | |||||
| for event_idx, event in enumerate(self.event_list.value[0]): | |||||
| directory = self.f[event].value.tostring().decode('utf-16') | |||||
| for im_idx, im in enumerate( | |||||
| self.f[self.file_list.value[0][event_idx]].value[0]): | |||||
| im_name = self.f[im].value.tostring().decode('utf-16') | |||||
| face_bbx = self.f[self.f[self.face_bbx_list.value | |||||
| [0][event_idx]].value[0][im_idx]].value | |||||
| bboxes = [] | |||||
| for i in range(face_bbx.shape[1]): | |||||
| xmin = int(face_bbx[0][i]) | |||||
| ymin = int(face_bbx[1][i]) | |||||
| xmax = int(face_bbx[0][i] + face_bbx[2][i]) | |||||
| ymax = int(face_bbx[1][i] + face_bbx[3][i]) | |||||
| bboxes.append((xmin, ymin, xmax, ymax)) | |||||
| yield DATA(os.path.join(self.path_to_image, directory, | |||||
| im_name + '.jpg'), bboxes) | |||||
| import h5py | |||||
| import os | |||||
| class DATA(object): | |||||
| def __init__(self, image_name, bboxes): | |||||
| self.image_name = image_name | |||||
| self.bboxes = bboxes | |||||
| class WIDER(object): | |||||
| def __init__(self, file_to_label, path_to_image): | |||||
| self.file_to_label = file_to_label | |||||
| self.path_to_image = path_to_image | |||||
| self.f = h5py.File(file_to_label, 'r') | |||||
| self.event_list = self.f.get('event_list') | |||||
| self.file_list = self.f.get('file_list') | |||||
| self.face_bbx_list = self.f.get('face_bbx_list') | |||||
| def next(self): | |||||
| for event_idx, event in enumerate(self.event_list.value[0]): | |||||
| directory = self.f[event].value.tostring().decode('utf-16') | |||||
| for im_idx, im in enumerate( | |||||
| self.f[self.file_list.value[0][event_idx]].value[0]): | |||||
| im_name = self.f[im].value.tostring().decode('utf-16') | |||||
| face_bbx = self.f[self.f[self.face_bbx_list.value | |||||
| [0][event_idx]].value[0][im_idx]].value | |||||
| bboxes = [] | |||||
| for i in range(face_bbx.shape[1]): | |||||
| xmin = int(face_bbx[0][i]) | |||||
| ymin = int(face_bbx[1][i]) | |||||
| xmax = int(face_bbx[0][i] + face_bbx[2][i]) | |||||
| ymax = int(face_bbx[1][i] + face_bbx[3][i]) | |||||
| bboxes.append((xmin, ymin, xmax, ymax)) | |||||
| yield DATA(os.path.join(self.path_to_image, directory, | |||||
| im_name + '.jpg'), bboxes) | |||||
| @@ -1,10 +1,10 @@ | |||||
| from core.image_reader import TrainImageReader | |||||
| from dface.core.image_reader import TrainImageReader | |||||
| import datetime | import datetime | ||||
| import os | import os | ||||
| from core.models import PNet,RNet,ONet,LossFn | |||||
| from dface.core.models import PNet,RNet,ONet,LossFn | |||||
| import torch | import torch | ||||
| from torch.autograd import Variable | from torch.autograd import Variable | ||||
| import core.image_tools as image_tools | |||||
| import dface.core.image_tools as image_tools | |||||
| @@ -1,8 +1,8 @@ | |||||
| import argparse | import argparse | ||||
| import sys | import sys | ||||
| from core.imagedb import ImageDB | |||||
| from dface.core.imagedb import ImageDB | |||||
| import train as train | import train as train | ||||
| import config | |||||
| import dface.config as config | |||||
| import os | import os | ||||
| @@ -1,8 +1,8 @@ | |||||
| import argparse | import argparse | ||||
| import sys | import sys | ||||
| from core.imagedb import ImageDB | |||||
| from dface.core.imagedb import ImageDB | |||||
| from train import train_pnet | from train import train_pnet | ||||
| import config | |||||
| import dface.config | |||||
| import os | import os | ||||
| @@ -1,8 +1,8 @@ | |||||
| import argparse | import argparse | ||||
| import sys | import sys | ||||
| from core.imagedb import ImageDB | |||||
| from dface.core.imagedb import ImageDB | |||||
| import train as train | import train as train | ||||
| import config | |||||
| import dface.config | |||||
| import os | import os | ||||
| @@ -1,7 +1,6 @@ | |||||
| import cv2 | import cv2 | ||||
| from core.detect import create_mtcnn_net, MtcnnDetector | |||||
| import core.vision as vision | |||||
| from dface.core.detect import create_mtcnn_net, MtcnnDetector | |||||
| from dface.core import vision | |||||