本文整理汇总了Python中detector.Detector.restore_from_ckpt方法的典型用法代码示例。如果您正苦于以下问题:Python Detector.restore_from_ckpt方法的具体用法?Python Detector.restore_from_ckpt怎么用?Python Detector.restore_from_ckpt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类detector.Detector
的用法示例。
在下文中一共展示了Detector.restore_from_ckpt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import restore_from_ckpt [as 别名]
def main(argv=None): # pylint: disable=unused-argument
assert args.ckpt > 0 or args.batch_eval
assert args.detect or args.segment, "Either detect or segment should be True"
if args.trunk == 'resnet50':
net = ResNet
depth = 50
if args.trunk == 'resnet101':
net = ResNet
depth = 101
if args.trunk == 'vgg16':
net = VGG
depth = 16
net = net(config=net_config, depth=depth, training=False)
if args.dataset == 'voc07' or args.dataset == 'voc07+12':
loader = VOCLoader('07', 'test')
if args.dataset == 'voc12':
loader = VOCLoader('12', 'val', segmentation=args.segment)
if args.dataset == 'coco':
loader = COCOLoader(args.split)
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)
if args.dataset == 'coco':
tester = COCOEval(detector, loader)
else:
tester = Evaluation(detector, loader, iou_thresh=args.voc_iou_thresh)
if not args.batch_eval:
detector.restore_from_ckpt(args.ckpt)
tester.evaluate_network(args.ckpt)
else:
log.info('Evaluating %s' % args.run_name)
ckpts_folder = CKPT_ROOT + args.run_name + '/'
out_file = ckpts_folder + evaluation_logfile
max_checked = get_last_eval(out_file)
log.debug("Maximum checked ckpt is %i" % max_checked)
with open(out_file, 'a') as f:
start = max(args.min_ckpt, max_checked+1)
ckpt_files = glob(ckpts_folder + '*.data*')
folder_has_nums = np.array(list((map(filename2num, ckpt_files))), dtype='int')
nums_available = sorted(folder_has_nums[folder_has_nums >= start])
nums_to_eval = [nums_available[-1]]
for n in reversed(nums_available):
if nums_to_eval[-1] - n >= args.step:
nums_to_eval.append(n)
nums_to_eval.reverse()
for ckpt in nums_to_eval:
log.info("Evaluation of ckpt %i" % ckpt)
tester.reset()
detector.restore_from_ckpt(ckpt)
res = tester.evaluate_network(ckpt)
f.write(res)
f.flush()
示例2: main
# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import restore_from_ckpt [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')
示例3: Application
# 需要导入模块: from detector import Detector [as 别名]
# 或者: from detector.Detector import restore_from_ckpt [as 别名]
class Application(tk.Frame):
def __init__(self, master=None, sess=None):
super().__init__(master)
self.root=master
self.root.resizable(width=1, height=1)
self.size = 1200
self.pack()
self.create_widgets()
self.view_classes = True
self.sess = sess
self.init_detectot()
def load_file(self):
fname = askopenfilename(filetypes=(("jpeg files", "*.jpg"),
("all files","*.*")),
initialdir=init_dir)
if fname:
try:
self.filename = fname
self.last_path = fname
self.change_image(path=fname)
except Exception as e: # <- naked except is a bad idea
showerror("Open Source File", "Failed to read file\n'%s'" % fname)
print(e)
return
def create_widgets(self):
# Run BlitzNet button
self.run = tk.Button(self, text='Run BlitzNet',
command=self.run_blitznet,
fg='green', width=self.size // 8)
self.run.pack(side="top")
# 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]
#.........这里部分代码省略.........