Skip to content

Commit

Permalink
compatible with python3
Browse files Browse the repository at this point in the history
  • Loading branch information
kuaikuaikim committed Dec 27, 2017
1 parent dd6cb77 commit 65bb658
Show file tree
Hide file tree
Showing 31 changed files with 81 additions and 81 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions src/core/detect.py → dface/core/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import numpy as np
import torch
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):
Expand Down Expand Up @@ -623,7 +623,7 @@ def detect_face(self,img):

t3 = time.time() - t
t = time.time()
print "time cost " + '{:.3f}'.format(t1+t2+t3) + ' pnet {:.3f} rnet {:.3f} onet {:.3f}'.format(t1, t2, t3)
print("time cost " + '{:.3f}'.format(t1+t2+t3) + ' pnet {:.3f} rnet {:.3f} onet {:.3f}'.format(t1, t2, t3))

return boxes_align, landmark_align

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/core/imagedb.py → dface/core/imagedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def append_flipped_images(self, imdb):
imdb: dict
image database with flipped image annotations added
"""
print 'append flipped images to imdb', len(imdb)
print('append flipped images to imdb', len(imdb))
for i in range(len(imdb)):
imdb_ = imdb[i]
m_bbox = imdb_['bbox_target'].copy()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import config
import assemble as assemble
import dface.config as config
import dface.prepare_data.assemble as assemble


if __name__ == '__main__':
Expand All @@ -22,4 +22,4 @@
imglist_file = os.path.join(anno_dir, imglist_filename)

chose_count = assemble.assemble_data(imglist_file ,anno_list)
print "PNet train annotation result file path:%s" % imglist_file
print("PNet train annotation result file path:%s" % imglist_file)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import config
import assemble as assemble
import dface.config as config
import dface.prepare_data.assemble as assemble


if __name__ == '__main__':
Expand All @@ -22,4 +22,4 @@
imglist_file = os.path.join(anno_dir, imglist_filename)

chose_count = assemble.assemble_data(imglist_file ,anno_list)
print "PNet train annotation result file path:%s" % imglist_file
print("PNet train annotation result file path:%s" % imglist_file)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import config
import assemble as assemble
import dface.config as config
import dface.prepare_data.assemble as assemble


if __name__ == '__main__':
Expand All @@ -22,4 +22,4 @@
imglist_file = os.path.join(anno_dir, imglist_filename)

chose_count = assemble.assemble_data(imglist_file ,anno_list)
print "PNet train annotation result file path:%s" % imglist_file
print("PNet train annotation result file path:%s" % imglist_file)
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import time
import os
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_onet_data(data_dir, anno_file, pnet_model_file, rnet_model_file, prefix_path='', use_cuda=True, vis=False):

Expand All @@ -27,7 +27,7 @@ def gen_onet_data(data_dir, anno_file, pnet_model_file, rnet_model_file, prefix_

for databatch in image_reader:
if batch_idx % 100 == 0:
print "%d images done" % batch_idx
print("%d images done" % batch_idx)
im = databatch

t = time.time()
Expand Down Expand Up @@ -89,7 +89,7 @@ def gen_onet_sample_data(data_dir,anno_file,det_boxs_file):
im_idx_list = list()
gt_boxes_list = list()
num_of_images = len(annotations)
print "processing %d images in total" % num_of_images
print("processing %d images in total" % num_of_images)

for annotation in annotations:
annotation = annotation.strip().split(' ')
Expand All @@ -112,7 +112,7 @@ def gen_onet_sample_data(data_dir,anno_file,det_boxs_file):
det_handle = open(det_boxs_file, 'r')

det_boxes = cPickle.load(det_handle)
print len(det_boxes), num_of_images
print(len(det_boxes), num_of_images)
assert len(det_boxes) == num_of_images, "incorrect detections or ground truths"

# index of neg, pos and part face, used as their image names
Expand All @@ -122,7 +122,7 @@ def gen_onet_sample_data(data_dir,anno_file,det_boxs_file):
image_done = 0
for im_idx, dets, gts in zip(im_idx_list, det_boxes, gt_boxes_list):
if image_done % 100 == 0:
print "%d images done" % image_done
print("%d images done" % image_done)
image_done += 1

if dets.shape[0] == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import cv2
import os
import numpy.random as npr
from core.utils import IoU
import config
from dface.core.utils import IoU
import dface.config as config



Expand Down Expand Up @@ -34,7 +34,7 @@ def gen_pnet_data(data_dir,anno_file):
annotations = f.readlines()

num = len(annotations)
print "%d pics in total" % num
print("%d pics in total" % num)
p_idx = 0
n_idx = 0
d_idx = 0
Expand All @@ -48,7 +48,7 @@ def gen_pnet_data(data_dir,anno_file):
img = cv2.imread(im_path)
idx += 1
if idx % 100 == 0:
print idx, "images done"
print(idx, "images done")

height, width, channel = img.shape

Expand Down Expand Up @@ -147,7 +147,7 @@ def gen_pnet_data(data_dir,anno_file):
cv2.imwrite(save_file, resized_im)
d_idx += 1
box_idx += 1
print "%s images done, pos: %s part: %s neg: %s"%(idx, p_idx, d_idx, n_idx)
print("%s images done, pos: %s part: %s neg: %s"%(idx, p_idx, d_idx, n_idx))

f1.close()
f2.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import cv2
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 os
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):

Expand All @@ -28,7 +28,7 @@ def gen_rnet_data(data_dir, anno_file, pnet_model_file, prefix_path='', use_cuda

for databatch in image_reader:
if batch_idx % 100 == 0:
print "%d images done" % batch_idx
print("%d images done" % batch_idx)
im = databatch

t = time.time()
Expand Down Expand Up @@ -85,7 +85,7 @@ def gen_rnet_sample_data(data_dir,anno_file,det_boxs_file):
im_idx_list = list()
gt_boxes_list = list()
num_of_images = len(annotations)
print "processing %d images in total" % num_of_images
print("processing %d images in total" % num_of_images)

for annotation in annotations:
annotation = annotation.strip().split(' ')
Expand Down Expand Up @@ -118,7 +118,7 @@ def gen_rnet_sample_data(data_dir,anno_file,det_boxs_file):
image_done = 0
for im_idx, dets, gts in zip(im_idx_list, det_boxes, gt_boxes_list):
if image_done % 100 == 0:
print "%d images done" % image_done
print("%d images done" % image_done)
image_done += 1

if dets.shape[0] == 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import sys
import numpy.random as npr
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):
Expand Down Expand Up @@ -34,7 +34,7 @@ def gen_data(anno_file, data_dir, prefix):
annotations = f2.readlines()

num = len(annotations)
print "%d pics in total" % num
print("%d pics in total" % num)

l_idx =0
idx = 0
Expand Down Expand Up @@ -68,7 +68,7 @@ def gen_data(anno_file, data_dir, prefix):

idx = idx + 1
if idx % 100 == 0:
print "%d images done, landmark images: %d"%(idx,l_idx)
print("%d images done, landmark images: %d"%(idx,l_idx))

x1, y1, x2, y2 = gt_box

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import sys
import numpy.random as npr
import argparse
import config
import core.utils as utils
import dface.config as config
import dface.core.utils as utils



Expand Down Expand Up @@ -35,7 +35,7 @@ def gen_data(anno_file, data_dir, prefix):
annotations = f2.readlines()

num = len(annotations)
print "%d total images" % num
print("%d total images" % num)

l_idx =0
idx = 0
Expand Down Expand Up @@ -67,7 +67,7 @@ def gen_data(anno_file, data_dir, prefix):

idx = idx + 1
if idx % 100 == 0:
print "%d images done, landmark images: %d"%(idx,l_idx)
print("%d images done, landmark images: %d"%(idx,l_idx))

x1, y1, x2, y2 = gt_box

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import sys
import numpy.random as npr
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):
Expand All @@ -34,7 +34,7 @@ def gen_data(anno_file, data_dir, prefix):
annotations = f2.readlines()

num = len(annotations)
print "%d total images" % num
print("%d total images" % num)

l_idx =0
idx = 0
Expand Down Expand Up @@ -66,7 +66,7 @@ def gen_data(anno_file, data_dir, prefix):

idx = idx + 1
if idx % 100 == 0:
print "%d images done, landmark images: %d"%(idx,l_idx)
print("%d images done, landmark images: %d"%(idx,l_idx))

x1, y1, x2, y2 = gt_box

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import time
import os
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):

Expand All @@ -27,7 +27,7 @@ def gen_landmark48_data(data_dir, anno_file, pnet_model_file, rnet_model_file, p

for databatch in image_reader:
if batch_idx % 100 == 0:
print "%d images done" % batch_idx
print("%d images done" % batch_idx)
im = databatch


Expand Down Expand Up @@ -91,7 +91,7 @@ def gen_sample_data(data_dir, anno_file, det_boxs_file, prefix_path =''):
gt_boxes_list = list()
gt_landmark_list = list()
num_of_images = len(annotations)
print "processing %d images in total" % num_of_images
print("processing %d images in total" % num_of_images)

for annotation in annotations:
annotation = annotation.strip().split(' ')
Expand All @@ -117,15 +117,15 @@ def gen_sample_data(data_dir, anno_file, det_boxs_file, prefix_path =''):
det_handle = open(det_boxs_file, 'r')

det_boxes = cPickle.load(det_handle)
print len(det_boxes), num_of_images
print(len(det_boxes), num_of_images)
assert len(det_boxes) == num_of_images, "incorrect detections or ground truths"

# index of neg, pos and part face, used as their image names
p_idx = 0
image_done = 0
for im_idx, dets, gts, landmark in zip(im_idx_list, det_boxes, gt_boxes_list, gt_landmark_list):
if image_done % 100 == 0:
print "%d images done" % image_done
print("%d images done" % image_done)
image_done += 1

if dets.shape[0] == 0:
Expand Down
File renamed without changes.
Loading

0 comments on commit 65bb658

Please sign in to comment.