Skip to content

Commit 0c3addd

Browse files
committed
Update to work for python3
1 parent 7133d9b commit 0c3addd

File tree

5 files changed

+29
-20
lines changed

5 files changed

+29
-20
lines changed

demo.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
plt.rcParams['image.interpolation'] = 'nearest'
55
plt.rcParams['image.cmap'] = 'gray'
66

7-
import os
8-
curdir=os.getcwd()
9-
import sys
10-
sys.path.insert(0,'../../python')
11-
7+
import os,platform,sys
8+
if platform.system()=="Windows":
9+
caffe_root="D:/CNN/ssd"#2
10+
else:
11+
caffe_root="/home/yanyu/Detection/ssd"
12+
sys.path.insert(0,caffe_root+'/python')
1213
import caffe
1314
caffe.set_device(0)
1415
caffe.set_mode_gpu()
1516
from google.protobuf import text_format
1617
from caffe.proto import caffe_pb2
1718
datasetname="Face2017"
1819
# load PASCAL VOC labels
19-
labelmap_file = curdir+'/labelmap_face.prototxt'
20+
labelmap_file = 'labelmap_face.prototxt'
2021
file = open(labelmap_file, 'r')
2122
labelmap = caffe_pb2.LabelMap()
2223
text_format.Merge(str(file.read()), labelmap)
@@ -28,7 +29,7 @@ def get_labelname(labelmap, labels):
2829
labels = [labels]
2930
for label in labels:
3031
found = False
31-
for i in xrange(0, num_labels):
32+
for i in range(0, num_labels):
3233
if label == labelmap.item[i].label:
3334
found = True
3435
labelnames.append(labelmap.item[i].display_name)
@@ -38,8 +39,8 @@ def get_labelname(labelmap, labels):
3839
#model_def =curdir+"/cpp/models/face_deploy.prototxt"
3940
#model_weights=curdir+"/cpp/models/VGG_Face2017_SSD_300x300_iter_120000.caffemodel"
4041
#image_resize = 300
41-
model_def =curdir+"/cpp/models/faceboxes_deploy.prototxt"
42-
model_weights=curdir+"/cpp/models/FaceBoxes_1024x1024.caffemodel"
42+
model_def ="cpp/models/faceboxes_deploy.prototxt"
43+
model_weights="cpp/models/FaceBoxes_1024x1024.caffemodel"
4344
image_resize = 1024
4445
net = caffe.Net(model_def, # defines the structure of the model
4546
model_weights, # contains the trained weights
@@ -85,13 +86,13 @@ def get_labelname(labelmap, labels):
8586
plt.imshow(image)
8687
currentAxis = plt.gca()
8788

88-
for i in xrange(top_conf.shape[0]):
89+
for i in range(top_conf.shape[0]):
8990
xmin = int(round(top_xmin[i] * image.shape[1]))
9091
ymin = int(round(top_ymin[i] * image.shape[0]))
9192
xmax = int(round(top_xmax[i] * image.shape[1]))
9293
ymax = int(round(top_ymax[i] * image.shape[0]))
9394
score = top_conf[i]
94-
print xmin,ymin,xmax,ymax,score
95+
print(xmin,ymin,xmax,ymax,score)
9596
label = int(top_label_indices[i])
9697
label_name = top_labels[i]
9798
display_txt = '%s: %.2f'%(label_name, score)

faceboxes_test.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# -*- coding: utf-8 -*
22
import numpy as np
3-
import sys,os,cv2
4-
caffe_root = 'D:/CNN/ssd'
3+
import sys,os,cv2,platform
4+
if platform.system()=="Windows":
5+
caffe_root="D:/CNN/ssd"
6+
else:
7+
caffe_root="/home/yanyu/Detection/ssd"
8+
sys.path.insert(0,caffe_root+'/python')
59
sys.path.insert(0, caffe_root + '/python')
610
import caffe
711
import time
@@ -48,7 +52,7 @@ def testimg(imgfile):
4852
time_start=time.time()
4953
out = net.forward()
5054
time_end=time.time()
51-
print time_end-time_start
55+
print(time_end-time_start)
5256
box, conf, cls = postprocess(frame, out)
5357
for i in range(len(box)):
5458
p1 = (box[i][0], box[i][1])
@@ -79,8 +83,7 @@ def detect(cameraindex=0):
7983
time_start=time.time()
8084
out = net.forward()
8185
time_end=time.time()
82-
print time_end-time_start,
83-
print "s"
86+
print(time_end-time_start)
8487

8588
box, conf, cls = postprocess(frame, out)
8689

ssd-face.pyproj

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<SchemaVersion>2.0</SchemaVersion>
66
<ProjectGuid>69443bc6-e3e9-42ba-a8d2-9c8075b1a700</ProjectGuid>
77
<ProjectHome>.</ProjectHome>
8-
<StartupFile>create_all.py</StartupFile>
8+
<StartupFile>faceboxes_test.py</StartupFile>
99
<SearchPath>
1010
</SearchPath>
1111
<WorkingDirectory>.</WorkingDirectory>
@@ -30,6 +30,7 @@
3030
<ItemGroup>
3131
<Compile Include="create_all.py" />
3232
<Compile Include="demo.py" />
33+
<Compile Include="faceboxes_test.py" />
3334
<Compile Include="test.py" />
3435
<Compile Include="train.py" />
3536
</ItemGroup>

test.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from __future__ import print_function
2-
import sys
3-
sys.path.append('python')
2+
import sys,platform
3+
if platform.system()=="Windows":
4+
caffe_root="D:/CNN/ssd"
5+
else:
6+
caffe_root="/home/yanyu/Detection/ssd"
7+
sys.path.insert(0,caffe_root+'/python')
48
import caffe
59
from caffe.model_libs import *
610
from google.protobuf import text_format

train.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import print_function
22
import sys,platform
33
if platform.system()=="Windows":
4-
caffe_root="D:/CNN/ssd"#2
4+
caffe_root="D:/CNN/ssd"
55
else:
66
caffe_root="/home/yanyu/Detection/ssd"
77
sys.path.insert(0,caffe_root+'/python')

0 commit comments

Comments
 (0)