本文整理汇总了Python中util.Timer.toc方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.toc方法的具体用法?Python Timer.toc怎么用?Python Timer.toc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Timer
的用法示例。
在下文中一共展示了Timer.toc方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from util import Timer [as 别名]
# 或者: from util.Timer import toc [as 别名]
def run(self, image_name, get_label=False, do_detection=1):
"""detection and extraction with max score box"""
### for web demo
#caffe.set_mode_gpu()
#print "do_detection: ",do_detection
if do_detection:
t1 = Timer()
t1.tic()
image = self.detect(image_name)
t1.toc('Detect time: ')
#print "Detection has done"
else:
image = cv2.imread(image_name)
#image = imresize(im, 300)
t2 = Timer()
t2.tic()
image = pad(image,size=224)
#image = pad(image)
features = extraction.forward(self.net_e, image, self.transformer)
r = np.squeeze(features['pool5/7x7_s1'].data[0])
#features2 = extraction.forward(self.net_e2, image, self.transformer2)
#r2 = np.squeeze(features2['pool5/7x7_s1'].data[0])
#r = r2
#r = np.hstack((r, r2)).copy()
t2.toc('extract time: ')
#start = time.time()
if self.pca is not None:
r = self.pca.transform(r)[0,:]
#print 'pca time: ', time.time() - start
r = r/norm(r)
if get_label:
label = np.squeeze(features['prob'].data[0].copy())
return r, label
return r
示例2: search
# 需要导入模块: from util import Timer [as 别名]
# 或者: from util.Timer import toc [as 别名]
def search(self, image_path, do_detection=1, k=10):
#queryImage = cv2.imread(image_path)
t1 = Timer()
t1.tic()
#queryFeatures = descriptor.get_descriptor(image_path, multi_box=False)
queryFeatures = descriptor.get_descriptor(image_path)
t1.toc('Feature Extraction time: ')
t2 = Timer()
t2.tic()
#p = Profile()
#results = p.runcall(self.searcher.search, queryFeatures)
#p.print_stats()
results, dists, ind = self.searcher.search(queryFeatures,k=5*k)
#self.reranking(queryFeatures, results, dists, ind, 0.6)
#self.queryExpansion2(results, dists, ind)
#self.queryExpansion(queryFeatures, results, dists, ind, top=3)
t2.toc('Knn search time: ')
result = []
# origine image
#result.append(image_path)
dist = []
for j,imageName in enumerate(results):
if imageName not in result:
result.append(imageName)
dist.append(dists[j])
#print result[:k]
return result[:k],dist[:k]
示例3: search
# 需要导入模块: from util import Timer [as 别名]
# 或者: from util.Timer import toc [as 别名]
def search(self, image_path, do_detection=0, k=20):
t1 = Timer()
t1.tic()
#queryFeatures = descriptor.get_descriptor(image_path, multi_box=False)
queryFeatures = descriptor.get_descriptor(image_path,do_detection=do_detection)
t1.toc('Feature Extraction time: ')
t2 = Timer()
t2.tic()
results, dists, ind = self.searcher.search(queryFeatures,k=k)
#self.queryExpansion(results, dists, ind)
#self.queryExpansion(results, dists, ind)
t2.toc('Knn search time: ')
result = []
dist = []
for j,imageName in enumerate(results):
if imageName not in result:
result.append(imageName)
dist.append(dists[j])
return result[:k],dist[:k]
示例4: detect
# 需要导入模块: from util import Timer [as 别名]
# 或者: from util.Timer import toc [as 别名]
def detect(self, image_name, multi_box=False, classes=CLASSES[1:]):
"""detect clothes in image"""
t1 = Timer()
t1.tic()
im = cv2.imread(image_name)
#im = imresize(im)
t1.toc('read image time: ')
t2 = Timer()
t2.tic()
scores, boxes = im_detect(self.net_d, im)
t2.toc('faster-rcnn time: ')
CONF_THRESH = 0.8
NMS_THRESH = 0.3
#dets = np.ones((5))
max_score = 0
if not multi_box:
f = open('bbox.txt','w')
for cls in classes:
cls_ind = CLASSES.index(cls)
cls_boxes = boxes[:, 4*cls_ind:4*(cls_ind + 1)]
cls_scores = scores[:, cls_ind]
box = np.hstack((cls_boxes, cls_scores[:,
np.newaxis])).astype(np.float32)
keep = nms(box, NMS_THRESH)
cls_boxes = box[keep, :4]
cls_scores = box[keep, 4]
score = max(cls_scores)
if score > CONF_THRESH:
ind = cls_scores.argmax()
max_score = score
det = cls_boxes[ind,:]
f.write(cls)
f.write('\n')
for d in det:
f.write(str(d))
f.write(' ')
#print cls
break
f.close()
if max_score == 0:
return im
else:
bbox = det.astype(np.float32)
#imshow(crop(im,bbox))
return crop(im,bbox)
else:
multi_im = []
dets = []
for cls in classes:
cls_ind = CLASSES.index(cls)
cls_boxes = boxes[:, 4*cls_ind:4*(cls_ind + 1)]
cls_scores = scores[:, cls_ind]
box = np.hstack((cls_boxes, cls_scores[:,
np.newaxis])).astype(np.float32)
keep = nms(box, NMS_THRESH)
cls_boxes = box[keep, :4]
cls_scores = box[keep, 4]
score = max(cls_scores)
if score > CONF_THRESH:
max_score = score
ind = cls_scores.argmax()
det = cls_boxes[ind,:]
if cls == '7' and (det[3]-det[1])<im.shape[0]/4 and det[3]>im.shape[0]-30:
break
if cls == '1' or cls == '4':
dets.append(det.copy())
break
dets.append(det.copy())
if max_score == 0:
multi_im.append(im)
return multi_im
else:
for det in dets:
bbox = det.astype(np.float32)
multi_im.append(crop(im,bbox))
return multi_im