本文整理汇总了Python中detector.Detector.feed_forward方法的典型用法代码示例。如果您正苦于以下问题:Python Detector.feed_forward方法的具体用法?Python Detector.feed_forward怎么用?Python Detector.feed_forward使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类detector.Detector
的用法示例。
在下文中一共展示了Detector.feed_forward方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import feed_forward [as 别名]
def main(argv=None): # pylint: disable=unused-argument
assert args.detect or args.segment, "Either detect or segment should be True"
assert args.ckpt > 0, "Specify the number of checkpoint"
net = ResNet(config=net_config, depth=50, training=False)
loader = Loader(osp.join(EVAL_DIR, 'demodemo'))
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True,
log_device_placement=False)) as sess:
detector = Detector(sess, net, loader, net_config, no_gt=args.no_seg_gt,
folder=osp.join(loader.folder, 'output'))
detector.restore_from_ckpt(args.ckpt)
for name in loader.get_filenames():
image = loader.load_image(name)
h, w = image.shape[:2]
print('Processing {}'.format(name + loader.data_format))
detector.feed_forward(img=image, name=name, w=w, h=h, draw=True,
seg_gt=None, gt_bboxes=None, gt_cats=None)
print('Done')
示例2: Application
# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import feed_forward [as 别名]
#.........这里部分代码省略.........
# Brows button
self.button = tk.Button(self, text="Browse",
command=self.load_file,
width=self.size // 8)
self.button.pack()
# from clipboard button
self.clip = tk.Button(self, text="From Clipboard",
command=self.from_clipboard,
width=self.size // 8)
self.clip.pack()
# Quit button
self.switch = tk.Button(self, text='View Classes', fg="red",
width=self.size // 8,
command=self.image_switch)
self.switch.pack(side="bottom")
# Image to be detected
# path = '/home/nik/Downloads/lock.jpeg'
# img = ImageTk.PhotoImage(Image.open(path).resize((self.size, self.size)))
img = make_teaser(self.size, colors)
img = ImageTk.PhotoImage(img)
self.panel = tk.Label(self.root, image=img)
self.panel.image = img
self.panel.pack(side = "bottom", fill = "both", expand = "yes")
def image_switch(self):
if self.view_classes:
self.view_classes = False
self.switch.text = "View Classes"
self.change_image(path=self.last_path)
else:
self.view_classes = True
self.switch.text = "View Image"
img = make_teaser(self.size, colors)
self.change_image(img=img)
def change_image(self, path=None, img=None):
img = image_on_fixed_canvas(Image.open(path), self.size) if img is None else img
img = ImageTk.PhotoImage(img)
self.panel.configure(image=img)
self.panel.image = img
def from_clipboard(self):
clipboard = self.clipboard_get()
print(clipboard)
self.filename = download_link(clipboard)
self.last_path = self.filename
self.change_image(path=self.filename)
def init_detectot(self):
assert args.detect or args.segment, "Either detect or segment should be True"
assert args.ckpt > 0, "Specify the number of checkpoint"
net = ResNet(config=net_config, depth=50, training=False)
self.loader = Loader(opj(EVAL_DIR, 'demodemo'))
self.detector = Detector(self.sess, net, self.loader, net_config, no_gt=args.no_seg_gt,
folder=opj(self.loader.folder, 'output'))
self.detector.restore_from_ckpt(args.ckpt)
def run_blitznet(self):
name = self.filename.split('/')[-1].split('.')[0]
image = self.loader.load_image(path=self.filename)
h, w = image.shape[:2]
print('Processing {}'.format(name + self.loader.data_format))
output = self.detector.feed_forward(img=image, name=name, w=w, h=h, draw=False,
seg_gt=None, gt_bboxes=None, gt_cats=None)
boxes, scores, cats, mask, _ = output
proc_img = self.draw(self.filename, name, boxes, scores, cats, mask)
self.change_image(path=opj(EVAL_DIR, 'demodemo', 'output', name
+ '_processed' + self.loader.data_format))
print('Done')
def draw(self, img_path, name, dets, scores, cats, mask):
image = Image.open(img_path)
w, h = image.size
mask = imresize(mask, (h, w), order=0, preserve_range=True).astype(int)
image = put_transparent_mask(image, mask, palette)
dr = ImageDraw.Draw(image)
for i in range(len(cats)):
cat = cats[i]
score = scores[i]
bbox = np.array(dets[i])
bbox[[2, 3]] += bbox[[0, 1]]
color = colors[cat]
draw_rectangle(dr, bbox, color, width=5)
dr.text(bbox[:2], self.loader.ids_to_cats[cat] + ' ' + str(score)[:4],
fill=color, font=font)
path_to_save = opj(EVAL_DIR, 'demodemo', 'output',
name + '_processed' + self.loader.data_format)
image.save(path_to_save, 'JPEG')
self.last_path = path_to_save
self.view_classes = False
return image