Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

push to fix the code on python3 and opencv3 #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.pyc
*.swp

#folder
*/__pycache__
data
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Add *:
`Modify the code to make it run sucessfully on Windows10 (python3.5+,tenforflow,opencv3)`

## YOLO_tensorflow

Tensorflow implementation of [YOLO](https://arxiv.org/pdf/1506.02640.pdf), including training and test phase.
Expand Down
7 changes: 4 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, net, weight_file):
self.sess = tf.Session()
self.sess.run(tf.global_variables_initializer())

print 'Restoring weights from: ' + self.weights_file
print ('Restoring weights from: ' + self.weights_file)
self.saver = tf.train.Saver()
self.saver.restore(self.sess, self.weights_file)

Expand All @@ -40,7 +40,7 @@ def draw_result(self, img, result):
cv2.rectangle(img, (x - w, y - h), (x + w, y + h), (0, 255, 0), 2)
cv2.rectangle(img, (x - w, y - h - 20),
(x + w, y - h), (125, 125, 125), -1)
cv2.putText(img, result[i][0] + ' : %.2f' % result[i][5], (x - w + 5, y - h - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1, cv2.CV_AA)
cv2.putText(img, result[i][0] + ' : %.2f' % result[i][5], (x - w + 5, y - h - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1, cv2.LINE_AA)

def detect(self, img):
img_h, img_w, _ = img.shape
Expand Down Expand Up @@ -169,6 +169,7 @@ def main():
parser.add_argument('--weight_dir', default='weights', type=str)
parser.add_argument('--data_dir', default="data", type=str)
parser.add_argument('--gpu', default='', type=str)
parser.add_argument('--file_name',default="person.jpg",type=str)
args = parser.parse_args()

os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu
Expand All @@ -182,7 +183,7 @@ def main():
# detector.camera_detector(cap)

# detect from image file
imname = 'test/person.jpg'
imname = 'test/'+args.file_name
detector.image_detector(imname)


Expand Down
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def train(self):
train_timer = Timer()
load_timer = Timer()

for step in xrange(1, self.max_iter + 1):
for step in range(1, self.max_iter + 1):

load_timer.tic()
images, labels = self.data.get()
Expand Down
12 changes: 6 additions & 6 deletions utils/pascal_voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import xml.etree.ElementTree as ET
import numpy as np
import cv2
import cPickle
import pickle
import copy
import yolo.config as cfg

Expand All @@ -16,7 +16,7 @@ def __init__(self, phase, rebuild=False):
self.image_size = cfg.IMAGE_SIZE
self.cell_size = cfg.CELL_SIZE
self.classes = cfg.CLASSES
self.class_to_ind = dict(zip(self.classes, xrange(len(self.classes))))
self.class_to_ind = dict(zip(self.classes, range(len(self.classes))))
self.flipped = cfg.FLIPPED
self.phase = phase
self.rebuild = rebuild
Expand Down Expand Up @@ -59,8 +59,8 @@ def prepare(self):
for idx in range(len(gt_labels_cp)):
gt_labels_cp[idx]['flipped'] = True
gt_labels_cp[idx]['label'] = gt_labels_cp[idx]['label'][:, ::-1, :]
for i in xrange(self.cell_size):
for j in xrange(self.cell_size):
for i in range(self.cell_size):
for j in range(self.cell_size):
if gt_labels_cp[idx]['label'][i, j, 0] == 1:
gt_labels_cp[idx]['label'][i, j, 1] = self.image_size - 1 - gt_labels_cp[idx]['label'][i, j, 1]
gt_labels += gt_labels_cp
Expand All @@ -74,7 +74,7 @@ def load_labels(self):
if os.path.isfile(cache_file) and not self.rebuild:
print('Loading gt_labels from: ' + cache_file)
with open(cache_file, 'rb') as f:
gt_labels = cPickle.load(f)
gt_labels = pickle.load(f)
return gt_labels

print('Processing gt_labels from: ' + self.data_path)
Expand All @@ -100,7 +100,7 @@ def load_labels(self):
gt_labels.append({'imname': imname, 'label': label, 'flipped': False})
print('Saving gt_labels to: ' + cache_file)
with open(cache_file, 'wb') as f:
cPickle.dump(gt_labels, f)
pickle.dump(gt_labels, f)
return gt_labels

def load_pascal_annotation(self, index):
Expand Down
6 changes: 3 additions & 3 deletions yolo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

WEIGHTS_DIR = os.path.join(PASCAL_PATH, 'weight')

WEIGHTS_FILE = None
# WEIGHTS_FILE = os.path.join(DATA_PATH, 'weights', 'YOLO_small.ckpt')
#WEIGHTS_FILE = None
WEIGHTS_FILE = os.path.join(DATA_PATH, 'weights', 'YOLO_small.ckpt')

CLASSES = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus',
'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse',
Expand Down Expand Up @@ -59,7 +59,7 @@

STAIRCASE = True

BATCH_SIZE = 45
BATCH_SIZE = 4

MAX_ITER = 15000

Expand Down