nilboy / tensorflow-yolo Goto Github PK
View Code? Open in Web Editor NEWtensorflow implementation of 'YOLO : Real-Time Object Detection'(train and test)
tensorflow implementation of 'YOLO : Real-Time Object Detection'(train and test)
Hi,
How can I modify the demo.py file, so the input image would be different not only cat.jpg.
For example, now If I want to test another image I have to change the input in demo.py file, which is [np_img = cv2.imread('cat.jpg')], then, I will be able to run another image.
I want to test another image not cat.jpg?
thanks for your well-structure code, but I have a confusion in these lines.
tensorflow-yolo/yolo/net/yolo_tiny_net.py
198-206 lines
can you give a explantion on base_boxes
Caused by op u'while_1/Pad_1', defined at:
File "tools/train.py", line 22, in
solver = eval(solver_params['name'])(dataset, net, common_params, solver_params)
File "./yolo/solver/yolo_solver.py", line 32, in init
self.construct_graph()
File "./yolo/solver/yolo_solver.py", line 62, in construct_graph
self.total_loss, self.nilboy = self.net.loss(self.predicts, self.labels, self.objects_num)
File "./yolo/net/yolo_tiny_net.py", line 295, in loss
tuple_results = tf.while_loop(self.cond1, self.body1, [tf.constant(0), object_num, [class_loss, object_loss, noobject_loss, coord_loss], predict, label, nilboy])
File "/home/wahaha/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2626, in while_loop
result = context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/home/wahaha/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2459, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/home/wahaha/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2409, in _BuildLoop
body_result = body(*packed_vars_for_body)
File "./yolo/net/yolo_tiny_net.py", line 187, in body1
response = tf.pad(response, temp, "CONSTANT")
File "/home/wahaha/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/array_ops.py", line 1646, in pad
return gen_array_ops._pad(tensor, paddings, name=name)
File "/home/wahaha/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 2083, in _pad
name=name)
File "/home/wahaha/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 763, in apply_op
op_def=op_def)
File "/home/wahaha/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2395, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/home/wahaha/anaconda2/envs/tensorflow/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1264, in init
self._traceback = _extract_stack()
InvalidArgumentError (see above for traceback): Paddings must be non-negative: 9 -3
[[Node: while_1/Pad_1 = Pad[T=DT_FLOAT, Tpaddings=DT_INT32, _device="/job:localhost/replica:0/task:0/gpu:0"](while_1/ones_1, while_1/Reshape_2)]]
[[Node: gradients/local1/add_grad/tuple/control_dependency_1/_191 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_11242_gradients/local1/add_grad/tuple/control_dependency_1", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]]
What's the problem? @nilboy
Hi,
I found there are some types in this model like a person, a cat, and et. I wonder if I could add another type to this model? For example, could I create a type of the panda and train some pictures of panda. I have labelled some pictures in the dataset.
Thanks so much,
Peter
How to fine tune your model?
I don't have sufficient data to retrain your model from scratch.I want to fine tune your model on my data which has only two classes ?
Hello everyone,
When I use this yolo_tiny.ckpt to fine-tune the model in my own dataset, the result is quite bad.
I guess it results of the original kept file.
Is there anyone who can share a better ckpt?
Thank you~
No loading yolo_tiny.ckpt. Direct training yolo_net, it will occur error :AssertionError: Model diverged with loss = NaN.
Environment :
TensorFlow 1.0
Python 3.6 (anaconda3)
I download the code for python3 version, and the pretrained model, and the VOC2007 data, then began to train the model by:
python tools/train.py -c conf/train.cfg
BUT, still get the error which I found in a closed issue (#11)
I also checked yolo_tiny_net.py, and found it has already been changed to:
predicts = tf.concat(3, [class_probs, scales, boxes])
Could you please give me some clue? Thanks a lot!
Why you set the first fully connected layer's input dim 49 * 1024?
I have modified the code for one-object detection. Due to the lack of training samples (about 1,600 images), I add the data augmentation codes in text_dataset.py as follows:
def batch(self):
"""get batch
Returns:
images: 4-D ndarray [batch_size, height, width, 3]
labels: 3-D ndarray [batch_size, max_objects, 5]
objects_num: 1-D ndarray [batch_size]
"""
images = []
labels = []
objects_num = []
for i in range(self.batch_size):
image, label, object_num = self.image_label_queue.get()
image, label = self._augumentation(image, label, object_num)
images.append(image)
labels.append(label)
objects_num.append(object_num)
images = np.asarray(images, dtype=np.float32)
images = images/255 * 2 - 1 # 归一化[-1,1]
labels = np.asarray(labels, dtype=np.float32)
objects_num = np.asarray(objects_num, dtype=np.int32)
return images, labels, objects_num
def _augumentation(self, src_image, src_labels, object_num, bright_range=[0.5,1.5], translation_scale=0.8):
"""image augmentation: brightness, flip, translation.
Args:
src_image: 3-D ndarray
src_labels: 2-D list [self.max_objects, 5] (xcenter, ycenter, w, h, class_num)
object_num: object number in src_image
bright_range: brightness adjusting range
translation_scale: translation scale
Return:
image: 3-D ndarray
labels: 2-D list [self.max_objects, 5] (xcenter, ycenter, w, h, class_num)
"""
width = src_image.shape[1]
height = src_image.shape[0]
image = src_image.copy()
## brightness
bright_ratio = random.random()*(bright_range[1]-bright_range[0]) + bright_range[0]
image = image*bright_ratio
image[image<0] = 0
image[image>255] = 255
image = np.asarray(image, np.uint8)
labels = src_labels[:]
## mirror (flip)
flip = random.random()>0.5
if flip:
image = cv2.flip(image, 1)
for i in range(object_num):
xc = width - labels[i][0]
labels[i][0] = xc
## translation
labels_array = np.asarray(labels, np.float32)
offset_xmin = -np.min(labels_array[:,0]-labels_array[:,2]/2) #left
offset_xmax = np.min(width-(labels_array[:,0]+labels_array[:,2]/2)) #right
offset_ymin = -np.min(labels_array[:,1]-labels_array[:,3]/2) #up
offset_ymax = np.min(height-(labels_array[:,0]+labels_array[:,3]/2)) #down
offset_x = int(random.uniform(offset_xmin*translation_scale, offset_xmax*translation_scale))
offset_y = int(random.uniform(offset_ymin*translation_scale, offset_ymax*translation_scale))
M = np.float32([[1, 0, offset_x], [0, 1, offset_y]])
image = cv2.warpAffine(image, M, (width, height))
image = np.asarray(image, np.uint8)
for i in range(object_num):
xc = labels[i][0]
xc = xc + offset_x
labels[i][0] = xc
yc = labels[i][1]
yc = yc + offset_y
labels[i][1] = yc
return image, labels
when I just use the augmentation of brightness and flip, it's ok. But the error occurred when the translation operation is added.
the error happens in yolo_tiny_net.py: (function body1())
objects = tf.pad(objects, temp, "CONSTANT")
the error is that:
InvalidArgumentError: padding must be non-negative: 5 -1
so, is there any problems in my codes? (PS: I have run augmentation code independently and it works well.)
Can I use the nilboy information to calculate the accuracy?
hey, I modified the code for one-object detection, the number of training samples is about 1000. the model converges quickly and the class_loss is almost zero, the coord_loss is about 0.5, the noobject_loss is about 0.015, the object_loss is about 0.03, the weight_loss is 1.11. but I found that the model still perform worse on training data. so who can explain the phenomenon?
Traceback (most recent call last):
File "demo.py", line 77, in
saver.restore(sess, 'models/pretrain/yolo_tiny.ckpt')
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1457, in restore
{self.saver_def.filename_tensor_name: save_path})
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 778, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 982, in _run
feed_dict_string, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1032, in _do_run
target_list, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1052, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.NotFoundError: Tensor name "conv5/biases" not found in checkpoint files models/pretrain/yolo_tiny.ckpt
[[Node: save/RestoreV2_8 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2_8/tensor_names, save/RestoreV2_8/shape_and_slices)]]
Caused by op u'save/RestoreV2_8', defined at:
File "demo.py", line 75, in
saver = tf.train.Saver(net.trainable_collection)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1056, in init
self.build()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1086, in build
restore_sequentially=self._restore_sequentially)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 691, in build
restore_sequentially, reshape)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 407, in _AddRestoreOps
tensors = self.restore_op(filename_tensor, saveable, preferred_shard)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 247, in restore_op
[spec.tensor.dtype])[0])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_io_ops.py", line 669, in restore_v2
dtypes=dtypes, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1228, in init
self._traceback = _extract_stack()
NotFoundError (see above for traceback): Tensor name "conv5/biases" not found in checkpoint files models/pretrain/yolo_tiny.ckpt
[[Node: save/RestoreV2_8 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2_8/tensor_names, save/RestoreV2_8/shape_and_slices)]]
I've followed the README guide to train this model but after several days of training (1m steps) the resulting performance is sometimes worse than the starting checkpoint. The loss is going down comparing to the first couple steps but doesn't change much after 20000 steps or so. Here is what I have in the end:
2017-04-08 14:51:43.589313: step 999950, loss = 3.99 (57.7 examples/sec; 0.277 s
ec/batch)
2017-04-08 14:51:46.701805: step 999960, loss = 8.01 (54.5 examples/sec; 0.294 s
ec/batch)
2017-04-08 14:51:49.754212: step 999970, loss = 7.63 (48.0 examples/sec; 0.333 s
ec/batch)
2017-04-08 14:51:52.851173: step 999980, loss = 4.31 (58.4 examples/sec; 0.274 s
ec/batch)
2017-04-08 14:51:55.847565: step 999990, loss = 4.15 (55.3 examples/sec; 0.289 s
ec/batch)
But if you compare the results of running demo with yolo_tiny.ckpt and trained model.ckpt you can see that the result is far from perfect.
yolo_tiny.ckpt:
trained model.ckpt:
Anyone else experienced the same behavior?
Why only an object can be identified, other objects can't be identified?
Hey, I noticed that you replaced
"f.nn.l2_loss(no_I * (p_C - C)) * self.noobject_scale" with
"tf.nn.l2_loss(no_I * (p_C)) * self.noobject_scale".
But as I know, the paper adopted the former one. Why did you make such a change?
Hi there, sorry about that to post this here, i was trying to write yolo in torch but struggled the backward function for so many days, but the gradients are always exploding slowly, could you kindly shed a light on my codes? Thank you so much.
gradInput[{ {}, {}, 1, {}, {} }] = self.mse:backward(torch.cmul(self.x_buffer, x, coord_mask), tx)
gradInput[{ {}, {}, 2, {}, {} }] = self.mse:backward(torch.cmul(self.y_buffer, y, coord_mask), ty)
gradInput[{ {}, {}, 3, {}, {} }] = self.mse:backward(torch.cmul(self.w_buffer, w, coord_mask), tw)
gradInput[{ {}, {}, 4, {}, {} }] = self.mse:backward(torch.cmul(self.h_buffer, h, coord_mask), th)
gradInput[{ {}, {}, 5, {}, {} }] = self.mse:backward(torch.cmul(self.conf_buffer, conf, coord_mask), tconf)
gradInput[{ {}, {}, { 6, 5 + nC }, {}, {} }][self.cls_mask] = self.ce:backward(torch.cmul(self.cls_buffer, cls), tcls)
Hi, I rewrite this project
Can I add this project to microsoft sample-for-ai?
https://github.com/LeoCHANGcn/samples-for-ai
Thanks!
When I type in "python tools/train.py -c conf/train.cfg", it report the error:
Traceback (most recent call last):
File "tools/train.py", line 6, in
import yolo
File "./yolo/init.py", line 1, in
import dataset
ModuleNotFoundError: No module named 'dataset'
I'm using anaconda3 BTW.
Thank you for your help!
Thanks for your shared code.
When i finetuning YOLO_tiny.ckpt( python:2.7, tensorflow:1.4) ,the error occurred as following:
'''
2018-01-24 16:00:56.966984: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1120] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
Traceback (most recent call last):
File "tools/train.py", line 23, in
solver.solve()
File "./yolo/solver/yolo_solver.py", line 79, in solve
saver1.restore(sess, self.pretrain_path)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1666, in restore
{self.saver_def.filename_tensor_name: save_path})
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 889, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1120, in _run
feed_dict_tensor, options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1317, in _do_run
options, run_metadata)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1336, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.NotFoundError: Tensor name "conv3/weights" not found in checkpoint files /home/wqy/Desktop/csdn/lesson8_up/yolo01/tensorflow-yolo/models/pretrain/YOLO_tiny.ckpt
[[Node: save/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2_5/tensor_names, save/RestoreV2_5/shape_and_slices)]]
Caused by op u'save/RestoreV2_5', defined at:
File "tools/train.py", line 23, in
solver.solve()
File "./yolo/solver/yolo_solver.py", line 68, in solve
saver1 = tf.train.Saver(self.net.pretrained_collection, write_version=1)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1218, in init
self.build()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1227, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1263, in _build
build_save=build_save, build_restore=build_restore)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 751, in _build_internal
restore_sequentially, reshape)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 427, in _AddRestoreOps
tensors = self.restore_op(filename_tensor, saveable, preferred_shard)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 267, in restore_op
[spec.tensor.dtype])[0])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_io_ops.py", line 1021, in restore_v2
shape_and_slices=shape_and_slices, dtypes=dtypes, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2956, in create_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1470, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
NotFoundError (see above for traceback): Tensor name "conv3/weights" not found in checkpoint files /home/wqy/Desktop/yolo01/tensorflow-yolo/models/pretrain/YOLO_tiny.ckpt
[[Node: save/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2_5/tensor_names, save/RestoreV2_5/shape_and_slices)]]
'''
How can i to solve this problem?Thank you!
import sys
sys.path.append('./')
import time
from yolo.net.yolo_tiny_net import YoloTinyNet
import tensorflow as tf
import cv2
import numpy as np
classes_name = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train","tvmonitor"]
class Timer(object):
"""A simple timer."""
def __init__(self):
self.total_time = 0.
self.calls = 0
self.start_time = 0.
self.diff = 0.
self.average_time = 0.
def tic(self):
# using time.time instead of time.clock because time time.clock
# does not normalize for multi-threading
self.start_time = time.time()
def toc(self, average=True):
self.diff = time.time() - self.start_time
self.total_time += self.diff
self.calls += 1
self.average_time = self.total_time / self.calls
if average:
return self.average_time
else:
return self.diff
def process_predicts(resized_img, predicts, thresh=0.12):
"""
process the predicts of object detection with one image input.
Args:
resized_img: resized source image.
predicts: output of the model.
thresh: thresh of bounding box confidence.
Return:
predicts_dict: {"cat": [[x1, y1, x2, y2, scores1], [...]]}.
"""
p_classes = predicts[0, :, :, 0:20] # 20 classes.
C = predicts[0, :, :, 20:22] # two bounding boxes in one cell.
coordinate = predicts[0, :, :,22:] # all bounding boxes position.
p_classes = np.reshape(p_classes, (7, 7, 1, 20))
C = np.reshape(C, (7, 7, 2, 1))
P = C * p_classes # confidencefor all classes of all bounding boxes (cell_size, cell_size, bounding_box_num, class_num) = (7, 7, 2, 1).
predicts_dict = {}
for i in range(7):
for j in range(7):
temp_data = np.zeros_like(P, np.float32)
temp_data[i, j, :, :] = P[i, j, :, :]
position = np.argmax(temp_data) # refer to the class num (with maximum confidence) for every bounding box.
index = np.unravel_index(position, P.shape)
if P[index] > thresh:
class_num = index[-1]
coordinate = np.reshape(coordinate, (7, 7, 2, 4)) # (cell_size, cell_size, bbox_num_per_cell, coordinate)[xmin, ymin, xmax, ymax]
max_coordinate = coordinate[index[0], index[1], index[2], :]
xcenter = max_coordinate[0]
ycenter = max_coordinate[1]
w = max_coordinate[2]
h = max_coordinate[3]
xcenter = (index[1] + xcenter) * (448/7.0)
ycenter = (index[0] + ycenter) * (448/7.0)
w = w * 448
h = h * 448
xmin = 0 if (xcenter - w/2.0 < 0) else (xcenter - w/2.0)
ymin = 0 if (ycenter - h/2.0 < 0) else (ycenter - h/2.0)
xmax = resized_img.shape[0] if (xmin + w) > resized_img.shape[0] else (xmin + w)
ymax = resized_img.shape[1] if (ymin + h) > resized_img.shape[1] else (ymin + h)
class_name = classes_name[class_num]
predicts_dict.setdefault(class_name, [])
predicts_dict[class_name].append([int(xmin), int(ymin), int(xmax), int(ymax), P[index]])
return predicts_dict
def non_max_suppress(predicts_dict, threshold=0.5):
"""
implement non-maximum supression on predict bounding boxes.
Args:
predicts_dict: {"cat": [[x1, y1, x2, y2, scores1], [...]]}.
threshhold: iou threshold
Return:
predicts_dict processed by non-maximum suppression
"""
for object_name, bbox in predicts_dict.items():
bbox_array = np.array(bbox, dtype=np.float)
x1, y1, x2, y2, scores = bbox_array[:,0], bbox_array[:,1], bbox_array[:,2], bbox_array[:,3], bbox_array[:,4]
areas = (x2-x1+1) * (y2-y1+1)
#print "areas shape = ", areas.shape
order = scores.argsort()[::-1]
#print "order = ", order
keep = []
while order.size > 0:
i = order[0]
keep.append(i)
xx1 = np.maximum(x1[i], x1[order[1:]])
yy1 = np.maximum(y1[i], y1[order[1:]])
xx2 = np.minimum(x2[i], x2[order[1:]])
yy2 = np.minimum(y2[i], y2[order[1:]])
inter = np.maximum(0.0, xx2-xx1+1) * np.maximum(0.0, yy2-yy1+1)
iou = inter/(areas[i]+areas[order[1:]]-inter)
indexs = np.where(iou<=threshold)[0]
order = order[indexs+1]
bbox = bbox_array[keep]
predicts_dict[object_name] = bbox.tolist()
predicts_dict = predicts_dict
return predicts_dict
def plot_result(src_img, predicts_dict):
"""
plot bounding boxes on source image.
Args:
src_img: source image
predicts_dict: {"cat": [[x1, y1, x2, y2, scores1], [...]]}.
"""
height_ratio = src_img.shape[0]/448.0
width_ratio = src_img.shape[1]/448.0
for object_name, bbox in predicts_dict.items():
for box in bbox:
xmin, ymin, xmax, ymax, score = box
src_xmin = xmin * width_ratio
src_ymin = ymin * height_ratio
src_xmax = xmax * width_ratio
src_ymax = ymax * height_ratio
score = float("%.3f" %score)
cv2.rectangle(src_img, (int(src_xmin), int(src_ymin)), (int(src_xmax), int(src_ymax)), (0, 0, 255))
cv2.putText(src_img, object_name + str(score), (int(src_xmin), int(src_ymin)), 1, 2, (0, 0, 255))
cv2.imshow("result", src_img)
#cv2.imwrite("result.jpg", src_img)
if __name__ == '__main__':
common_params = {'image_size': 448, 'num_classes': 20, 'batch_size': 1}
net_params = {'cell_size': 7, 'boxes_per_cell': 2, 'weight_decay': 0.0005}
net = YoloTinyNet(common_params, net_params, test=True)
image = tf.placeholder(tf.float32, (1, 448, 448, 3))
predicts = net.inference(image)
sess = tf.Session()
src_img = cv2.imread("./data/VOCdevkit/VOC2007/JPEGImages/000101.jpg")
resized_img = cv2.resize(src_img, (448, 448))
#height_ratio = src_img.shape[0]/448.0
#width_ratio = src_img.shape[1]/448.0
# convert to rgb image
np_img = cv2.cvtColor(resized_img, cv2.COLOR_BGR2RGB)
# convert data type used in tf
np_img = np_img.astype(np.float32)
# data normalization and reshape to input tensor
np_img = np_img / 255.0 * 2 - 1
np_img = np.reshape(np_img, (1, 448, 448, 3))
saver = tf.train.Saver(net.trainable_collection)
saver.restore(sess, 'models/pretrain/yolo_tiny.ckpt')
timer = Timer()
timer.tic()
print('Procession detection...')
np_predict = sess.run(predicts, feed_dict={image: np_img})
timer.toc()
print('One detection took {:.3f}s in average'.format(timer.total_time))
predicts_dict = process_predicts(resized_img, np_predict)
print "predict dict: ", predicts_dict
predicts_dict = non_max_suppress(predicts_dict)
print "predict dict after non-maximum suppression: ", predicts_dict
plot_result(src_img, predicts_dict)
cv2.waitKey(0)
I am not sure if there is any problems in this code, At least it runs successfully in my pc. I hope this could help anyone who needs it. And I will be appreciate it if anyone could give some advice.
Hi
I'm new to ML and tensorflow.
I'm trying to use tensorflow-yolo to train model for hand recognition.
No. of classes is 1 which is hand
when I run train.py it returns Padding -ve error.
Caused by op u'while_2/Pad', defined at:
File "tools/train.py", line 22, in
solver = eval(solver_params['name'])(dataset, net, common_params, solver_params)
File "./yolo/solver/yolo_solver.py", line 32, in init
self.construct_graph()
File "./yolo/solver/yolo_solver.py", line 62, in construct_graph
self.total_loss, self.nilboy = self.net.loss(self.predicts, self.labels, self.objects_num)
File "./yolo/net/yolo_tiny_net.py", line 297, in loss
tuple_results = tf.while_loop(self.cond1, self.body1, [tf.constant(0), object_num, [class_loss, object_loss, noobject_loss, coord_loss], predict, label, nilboy])
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2775, in while_loop
result = context.BuildLoop(cond, body, loop_vars, shape_invariants)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2604, in BuildLoop
pred, body, original_loop_vars, loop_vars, shape_invariants)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/control_flow_ops.py", line 2554, in _BuildLoop
body_result = body(*packed_vars_for_body)
File "./yolo/net/yolo_tiny_net.py", line 175, in body1
objects = tf.pad(objects, temp, "CONSTANT")
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/array_ops.py", line 1679, in pad
return gen_array_ops._pad(tensor, paddings, name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 1989, in _pad
name=name)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op
op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 2630, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1204, in init
self._traceback = self._graph._extract_stack() # pylint: disable=protected-access
InvalidArgumentError (see above for traceback): Paddings must be non-negative: 4 -1
[[Node: while_2/Pad = Pad[T=DT_FLOAT, Tpaddings=DT_INT32, _device="/job:localhost/replica:0/task:0/gpu:0"](while_2/ones, while_2/Reshape_1)]]
[[Node: gradients/AddN_132/_185 = _Recvclient_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_49524_gradients/AddN_132", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]]
Do you have any idea cause of this issue?
Regards
Hello,
I wanna know if there is anyway to detect less classes (I'm interested in just one).
Thanks!
Hi, I tried to run this code with Branch "python 3". Howerver, as I have used the tensorflow ver1.0, the error "module 'tensorflow' has no attribute 'mul'" occurred in this file("./yolo/net/net.py");
then I replaced "tf.mul" with "tf.matmul", another error "ValueError: Shape must be rank 2 but is rank 0 for 'conv1/weight_loss' Mul'.... " occurred. As I am not good at python programming, I cannot put it right.
Noticing that you are still maintaining this project in Branch "python 2.7", so, can you help me solve this problem?(I ran this project with W7 x64, the python version is 3.5.2)
It seems that all variables on the graph are trainable because the "train" arg of "_variable_on_cpu" was not sent to "trainable" arg of tf.get_variable. So every time we run train_op, all variable will be updated. Is that correct ?
Hi, Nice work!
Can you kindly tell me how you generated/got the pre-trained model below?
yolo_tiny: https://drive.google.com/file/d/0B-yiAeTLLamRekxqVE01Yi1RRlk/view?usp=sharing
Hi,
I am running this program and really want to know if I could get the confidence probability of the result from demo.py?
Thanks,
Peter
Can you release the ckpt file for yolo_net?
I have tested your tiny-yolo on pascal_voc 2007 validation set. The result of test is so bad, I think. Do you use
paramters from darknet tiny_yolo or trained by yourself? Can your tiny_yolo reach MAP 50%?
I used this python3 branch to re implement your code. However, i have this error :'( Please help me
NotFoundError (see above for traceback): Unsuccessful TensorSliceReader construc
tor: Failed to find any matching files for F:\yolo_tiny.ckpt
[[Node: save/RestoreV2_5 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:l
ocalhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2_5/tensor_na
mes, save/RestoreV2_5/shape_and_slices)]]
Hi, thanks for your great work.
I notice that the output of the yolo is a 7730 tensor, and some of the output means Pr(class|object), and some means Pr(object), but these output may be <0, so they don't means probability any more.
How to understand these problems?
This looks like nice work! But I'm having some trouble interpreting the results and seeing how you do (and I could do) validation/testing (on validation/test set).
When I follow the instructions for training on the Pascal VOC dataset, exactly as you describe it, the system seems to start training fine, and progress can for example be monitored using TensorBoard (or just watching the command line output).
After about 14000 steps, I get:
2017-03-08 13:54:49.951253: step 13960, loss = 4.10 (49.3 examples/sec; 0.325 sec/batch)
2017-03-08 13:54:53.520895: step 13970, loss = 5.73 (45.7 examples/sec; 0.350 sec/batch)
2017-03-08 13:54:57.180532: step 13980, loss = 6.08 (37.5 examples/sec; 0.427 sec/batch)
2017-03-08 13:55:00.669307: step 13990, loss = 4.97 (50.1 examples/sec; 0.319 sec/batch)
2017-03-08 13:55:04.188500: step 14000, loss = 4.71 (50.0 examples/sec; 0.320 sec/batch)
2017-03-08 13:55:07.815220: step 14010, loss = 5.66 (44.7 examples/sec; 0.358 sec/batch)
But this is similar to the loss performance observed after only around 1300 steps or so.
What is the loss performance I should expect, and at how many steps (more or less)?
Is the conf/train.cfg you provide the exact same config file you used to obtain good performance?
And how do you do validation/testing on a separate dataset? Is there a separate function to call or should train.py be used with different parameters or something?
Hey, I found the "weight_decay" is initialized in yolo_net.py, but where does it be used?
Thanks for sharing your work. I tried the demo.py and it seems to work fine. I think I could understand more about YOLO.
However, I am slightly curious why it takes quite long. One single image query took 116 sec (model load 0.4, inference 115.5, post-process 0). I am seeing 9 conv + 3 fc layers. It must be only feed-forward. Such size usually takes that long? Do you have any idea? Is it tensorflow problem?
I have run the demo successfully,but 24 hours later,it's still running,and I am using 1080ti,Losses are always fluctuating between 5 and 10,I don't know whether the train has been finished,so I want to find the epoch_num,but I can't find it,anyone konw this?many thanks!
if I want to see the performance like mAp,what I should do?
I just want to try the demo, but I got this. Can anyone help me ?
2018-02-22 11:17:41.099700: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-02-22 11:17:41.099982: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1208] Found device 0 with properties:
name: GeForce GTX 1050 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.62
pciBusID: 0000:01:00.0
totalMemory: 3.94GiB freeMemory: 3.33GiB
2018-02-22 11:17:41.100000: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1308] Adding visible gpu devices: 0
2018-02-22 11:17:41.547405: I tensorflow/core/common_runtime/gpu/gpu_device.cc:989] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2985 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
Traceback (most recent call last):
File "demo.py", line 77, in
saver.restore(sess, 'models/pretrain/yolo_tiny.ckpt')
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/saver.py", line 1751, in restore
" to the checkpoint files." % save_path)
ValueError: The specified path: models/pretrain/yolo_tiny.ckpt is a file. Please specify only the path prefix to the checkpoint files.
when I tried the training and demo,the following error happened!
NotFoundError (see above for traceback): Tensor name "conv1/biases" not found in checkpoint files models/pretrain/yolo_tiny.ckpt
Hi
Could you please guide me how to train the net without using pretrained model?
I faced with this error when trying train without pretrained file:
NotFoundError (see above for traceback): Unsuccessful TensorSliceReader constructor: Failed to find any matching files for
[[Node: save/RestoreV2_8 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2_8/tensor_names, save/RestoreV2_8/shape_and_slices)]]
Thanks
Traceback (most recent call last):
File "E:\python_workspace\tensorflow-yolo\demo.py", line 5, in
from yolo.net.yolo_tiny_net import YoloTinyNet
File "E:\python_workspace\tensorflow-yolo\yolo_init_.py", line 2, in
import net
ModuleNotFoundError: No module named 'net'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.