dBeker / Faster-RCNN-TensorFlow-Python3

Tensorflow Faster R-CNN for Windows/Linux and Python 3 (3.5/3.6/3.7)
MIT License
609 stars 329 forks source link

about test #60

Closed PangJian123 closed 5 years ago

PangJian123 commented 5 years ago

i want to evaluate my dataset.who can help me ,thank you very much!!!

PangJian123 commented 5 years ago

I have solved the test problem,it can evaluate my own dataset under windows10 . Following next steps to evaluate your own dataset: First: make sure you can demo your own dataset Second:add following code to a new test_net.py Third:Input python test_net.py (the following code that i modified is not standard,i make this in order to evaluate AP and MAP.you can contact me If you have any questions)

# --------------------------------------------------------
# Tensorflow Faster R-CNN
# Licensed under The MIT License [see LICENSE for details]
# Written by Zheqi he, Xinlei Chen, based on code from Ross Girshick
# --------------------------------------------------------
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

# import _init_paths
from lib.utils.test import test_net
from lib.config import config as cfg
# from lib.config import cfg, cfg_from_file, cfg_from_list
from lib.datasets.factory import get_imdb
import argparse
import pprint
import time, os, sys

import tensorflow as tf
from lib.nets.vgg16 import vgg16
# from nets.resnet_v1 import resnetv1
# from nets.mobilenet_v1 import mobilenetv1

demonet = 'vgg16'
dataset = 'pascal_voc'
NETS = {'vgg16': ('vgg16.ckpt',)}
DATASETS = {'pascal_voc': ('voc_2007_trainval',)}
tfmodel = os.path.join('output', demonet, DATASETS[dataset][0], 'default', NETS[demonet][0])

def parse_args():
  """
  Parse input arguments
  """
  parser = argparse.ArgumentParser(description='Test a Fast R-CNN network')
  parser.add_argument('--cfg', dest='cfg_file',
            help='optional config file', default=None, type=str)
  parser.add_argument('--model', dest='model',
            help='model to test',
            default=None, type=str)
  parser.add_argument('--imdb', dest='imdb_name',
            help='dataset to test',
            default='voc_2007_test', type=str)
  parser.add_argument('--comp', dest='comp_mode', help='competition mode',
            action='store_true')
  parser.add_argument('--num_dets', dest='max_per_image',
            help='max number of detections per image',
            default=100, type=int)
  parser.add_argument('--tag', dest='tag',
                        help='tag of the model',
                        default='', type=str)
  # parser.add_argument('--net', dest='net',
  #                     help='vgg16, res50, res101, res152, mobile',
  #                     default='res50', type=str)
  parser.add_argument('--set', dest='set_cfgs',
                        help='set config keys', default=None,
                        nargs=argparse.REMAINDER)
  parser.add_argument('--net', dest='demo_net', help='Network to use [vgg16 res101]',
                      choices=NETS.keys(), default='vgg16')
  parser.add_argument('--dataset', dest='dataset', help='Trained dataset [pascal_voc pascal_voc_0712]',
                      choices=DATASETS.keys(), default='pascal_voc_0712')

  # if len(sys.argv) == 1:
  #   parser.print_help()
  #   sys.exit(1)

  args = parser.parse_args()                 # 解析参数
  return args

if __name__ == '__main__':
  args = parse_args()

  print('Called with args:')
  print(args)

  # if args.cfg_file is not None:
  #   cfg_from_file(args.cfg_file)
  # if args.set_cfgs is not None:
  #   cfg_from_list(args.set_cfgs)

  print('Using config:')
  pprint.pprint(cfg)

  # if has model, get the name from it
  # if does not, then just use the initialization weights
  if tfmodel:
    filename = os.path.splitext(os.path.basename(tfmodel))[0]
  else:
    filename = os.path.splitext(os.path.basename(args.weight))[0]

  tag = args.tag
  tag = tag if tag else 'default'
  filename = tag + '/' + filename

  imdb = get_imdb(args.imdb_name)
  imdb.competition_mode(args.comp_mode)

  tfconfig = tf.ConfigProto(allow_soft_placement=True)
  tfconfig.gpu_options.allow_growth=True

  # init session
  sess = tf.Session(config=tfconfig)
  # load network

  if demonet == 'vgg16':
      net = vgg16()
  # elif args.net == 'res50':
  #   net = resnetv1(num_layers=50)
  # elif args.net == 'res101':
  #   net = resnetv1(num_layers=101)
  # elif args.net == 'res152':
  #   net = resnetv1(num_layers=152)
  # elif args.net == 'mobile':
  #   net = mobilenetv1()
  else:
    raise NotImplementedError

  # load model
  net.create_architecture(sess, mode="TEST",num_classes=6, tag='default',
                          anchor_scales=[8, 16, 32],
                          anchor_ratios=[0.5, 1, 2])

  if tfmodel:
    print(('Loading model check point from {:s}').format(tfmodel))
    saver = tf.train.Saver()
    saver.restore(sess, tfmodel)
    print('Loaded.')
  else:
    print(('Loading initial weights from {:s}').format(args.weight))
    sess.run(tf.global_variables_initializer())
    print('Loaded.')

  test_net(sess, net, imdb, filename, max_per_image=args.max_per_image)

  sess.close()
dBeker commented 5 years ago

Can you send a PR including the changes?

forwardxu0129 commented 5 years ago

PendingDeprecationWarning: WARNING: TF Lite has moved from tf.contrib.lite to tf.lite. Please update your imports. This will be a breaking error in TensorFlow version 2.0. _warnings.warn(WARNING, PendingDeprecationWarning)

How can l solve it ??? anyone can help me ???

AriadneZhao commented 5 years ago

I have solved the test problem,it can evaluate my own dataset under windows10 . Following next steps to evaluate your own dataset: First: make sure you can demo your own dataset Second:add following code to a new test_net.py Third:Input python test_net.py (the following code that i modified is not standard,i make this in order to evaluate AP and MAP.you can contact me If you have any questions)

--------------------------------------------------------

Tensorflow Faster R-CNN

Licensed under The MIT License [see LICENSE for details]

Written by Zheqi he, Xinlei Chen, based on code from Ross Girshick

--------------------------------------------------------

from future import absolute_import from future import division from future import print_function

import _init_paths

from lib.utils.test import test_net from lib.config import config as cfg

from lib.config import cfg, cfg_from_file, cfg_from_list

from lib.datasets.factory import get_imdb import argparse import pprint import time, os, sys

import tensorflow as tf from lib.nets.vgg16 import vgg16

from nets.resnet_v1 import resnetv1

from nets.mobilenet_v1 import mobilenetv1

demonet = 'vgg16' dataset = 'pascal_voc' NETS = {'vgg16': ('vgg16.ckpt',)} DATASETS = {'pascal_voc': ('voc_2007_trainval',)} tfmodel = os.path.join('output', demonet, DATASETS[dataset][0], 'default', NETS[demonet][0])

def parse_args(): """ Parse input arguments """ parser = argparse.ArgumentParser(description='Test a Fast R-CNN network') parser.add_argument('--cfg', dest='cfg_file', help='optional config file', default=None, type=str) parser.add_argument('--model', dest='model', help='model to test', default=None, type=str) parser.add_argument('--imdb', dest='imdb_name', help='dataset to test', default='voc_2007_test', type=str) parser.add_argument('--comp', dest='comp_mode', help='competition mode', action='store_true') parser.add_argument('--num_dets', dest='max_per_image', help='max number of detections per image', default=100, type=int) parser.add_argument('--tag', dest='tag', help='tag of the model', default='', type=str)

parser.add_argument('--net', dest='net',

help='vgg16, res50, res101, res152, mobile',

default='res50', type=str)

parser.add_argument('--set', dest='set_cfgs', help='set config keys', default=None, nargs=argparse.REMAINDER) parser.add_argument('--net', dest='demo_net', help='Network to use [vgg16 res101]', choices=NETS.keys(), default='vgg16') parser.add_argument('--dataset', dest='dataset', help='Trained dataset [pascal_voc pascal_voc_0712]', choices=DATASETS.keys(), default='pascal_voc_0712')

if len(sys.argv) == 1:

parser.print_help()

sys.exit(1)

args = parser.parse_args() # 解析参数 return args

if name == 'main': args = parse_args()

print('Called with args:') print(args)

if args.cfg_file is not None:

cfg_from_file(args.cfg_file)

if args.set_cfgs is not None:

cfg_from_list(args.set_cfgs)

print('Using config:') pprint.pprint(cfg)

if has model, get the name from it

if does not, then just use the initialization weights

if tfmodel: filename = os.path.splitext(os.path.basename(tfmodel))[0] else: filename = os.path.splitext(os.path.basename(args.weight))[0]

tag = args.tag tag = tag if tag else 'default' filename = tag + '/' + filename

imdb = get_imdb(args.imdb_name) imdb.competition_mode(args.comp_mode)

tfconfig = tf.ConfigProto(allow_soft_placement=True) tfconfig.gpu_options.allow_growth=True

init session

sess = tf.Session(config=tfconfig)

load network

if demonet == 'vgg16': net = vgg16()

elif args.net == 'res50':

net = resnetv1(num_layers=50)

elif args.net == 'res101':

net = resnetv1(num_layers=101)

elif args.net == 'res152':

net = resnetv1(num_layers=152)

elif args.net == 'mobile':

net = mobilenetv1()

else: raise NotImplementedError

load model

net.create_architecture(sess, mode="TEST",num_classes=6, tag='default', anchor_scales=[8, 16, 32], anchor_ratios=[0.5, 1, 2])

if tfmodel: print(('Loading model check point from {:s}').format(tfmodel)) saver = tf.train.Saver() saver.restore(sess, tfmodel) print('Loaded.') else: print(('Loading initial weights from {:s}').format(args.weight)) sess.run(tf.global_variables_initializer()) print('Loaded.')

test_net(sess, net, imdb, filename, max_per_image=args.max_per_image)

sess.close()

it says that NameError: name 'imdb' is not defined. Could you please tell me how to solve this?

forwardxu0129 commented 5 years ago

https://blog.csdn.net/beyond_xnsx/article/details/79910900 你可以参考这个 ------------------ 原始邮件 ------------------ 发件人: "AriadneZhao"notifications@github.com; 发送时间: 2019年5月10日(星期五) 下午4:51 收件人: "dBeker/Faster-RCNN-TensorFlow-Python3.5"Faster-RCNN-TensorFlow-Python3.5@noreply.github.com; 抄送: "JASON"244075482@qq.com;"Comment"comment@noreply.github.com; 主题: Re: [dBeker/Faster-RCNN-TensorFlow-Python3.5] about test (#60)

I have solved the test problem,it can evaluate my own dataset under windows10 . Following next steps to evaluate your own dataset: First: make sure you can demo your own dataset Second:add following code to a new test_net.py Third:Input python test_net.py (the following code that i modified is not standard,i make this in order to evaluate AP and MAP.you can contact me If you have any questions)


Tensorflow Faster R-CNN

Licensed under The MIT License [see LICENSE for details]

Written by Zheqi he, Xinlei Chen, based on code from Ross Girshick


from future import absolute_import from future import division from future import print_function

import _init_paths

from lib.utils.test import test_net from lib.config import config as cfg

from lib.config import cfg, cfg_from_file, cfg_from_list

from lib.datasets.factory import get_imdb import argparse import pprint import time, os, sys

import tensorflow as tf from lib.nets.vgg16 import vgg16

from nets.resnet_v1 import resnetv1

from nets.mobilenet_v1 import mobilenetv1

demonet = 'vgg16' dataset = 'pascal_voc' NETS = {'vgg16': ('vgg16.ckpt',)} DATASETS = {'pascal_voc': ('voc_2007_trainval',)} tfmodel = os.path.join('output', demonet, DATASETS[dataset][0], 'default', NETS[demonet][0])

def parse_args(): """ Parse input arguments """ parser = argparse.ArgumentParser(description='Test a Fast R-CNN network') parser.add_argument('--cfg', dest='cfg_file', help='optional config file', default=None, type=str) parser.add_argument('--model', dest='model', help='model to test', default=None, type=str) parser.add_argument('--imdb', dest='imdb_name', help='dataset to test', default='voc_2007_test', type=str) parser.add_argument('--comp', dest='comp_mode', help='competition mode', action='store_true') parser.add_argument('--num_dets', dest='max_per_image', help='max number of detections per image', default=100, type=int) parser.add_argument('--tag', dest='tag', help='tag of the model', default='', type=str)

parser.add_argument('--net', dest='net',

help='vgg16, res50, res101, res152, mobile',

default='res50', type=str)

parser.add_argument('--set', dest='set_cfgs', help='set config keys', default=None, nargs=argparse.REMAINDER) parser.add_argument('--net', dest='demo_net', help='Network to use [vgg16 res101]', choices=NETS.keys(), default='vgg16') parser.add_argument('--dataset', dest='dataset', help='Trained dataset [pascal_voc pascal_voc_0712]', choices=DATASETS.keys(), default='pascal_voc_0712')

if len(sys.argv) == 1:

parser.print_help()

sys.exit(1)

args = parser.parse_args() # 解析参数 return args

if name == 'main': args = parse_args()

print('Called with args:') print(args)

if args.cfg_file is not None:

cfg_from_file(args.cfg_file)

if args.set_cfgs is not None:

cfg_from_list(args.set_cfgs)

print('Using config:') pprint.pprint(cfg)

if has model, get the name from it

if does not, then just use the initialization weights

if tfmodel: filename = os.path.splitext(os.path.basename(tfmodel))[0] else: filename = os.path.splitext(os.path.basename(args.weight))[0]

tag = args.tag tag = tag if tag else 'default' filename = tag + '/' + filename

imdb = get_imdb(args.imdb_name) imdb.competition_mode(args.comp_mode)

tfconfig = tf.ConfigProto(allow_soft_placement=True) tfconfig.gpu_options.allow_growth=True

init session

sess = tf.Session(config=tfconfig)

load network

if demonet == 'vgg16': net = vgg16()

elif args.net == 'res50':

net = resnetv1(num_layers=50)

elif args.net == 'res101':

net = resnetv1(num_layers=101)

elif args.net == 'res152':

net = resnetv1(num_layers=152)

elif args.net == 'mobile':

net = mobilenetv1()

else: raise NotImplementedError

load model

net.create_architecture(sess, mode="TEST",num_classes=6, tag='default', anchor_scales=[8, 16, 32], anchor_ratios=[0.5, 1, 2])

if tfmodel: print(('Loading model check point from {:s}').format(tfmodel)) saver = tf.train.Saver() saver.restore(sess, tfmodel) print('Loaded.') else: print(('Loading initial weights from {:s}').format(args.weight)) sess.run(tf.global_variables_initializer()) print('Loaded.')

test_net(sess, net, imdb, filename, max_per_image=args.max_per_image)

sess.close()

it says that NameError: name 'imdb' is not defined. Could you please tell me how to solve this?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

MsRabbits commented 5 years ago

I have solved the test problem,it can evaluate my own dataset under windows10 . Following next steps to evaluate your own dataset: First: make sure you can demo your own dataset Second:add following code to a new test_net.py Third:Input python test_net.py (the following code that i modified is not standard,i make this in order to evaluate AP and MAP.you can contact me If you have any questions)

--------------------------------------------------------

Tensorflow Faster R-CNN

Licensed under The MIT License [see LICENSE for details]

Written by Zheqi he, Xinlei Chen, based on code from Ross Girshick

--------------------------------------------------------

from future import absolute_import from future import division from future import print_function

import _init_paths

from lib.utils.test import test_net from lib.config import config as cfg

from lib.config import cfg, cfg_from_file, cfg_from_list

from lib.datasets.factory import get_imdb import argparse import pprint import time, os, sys

import tensorflow as tf from lib.nets.vgg16 import vgg16

from nets.resnet_v1 import resnetv1

from nets.mobilenet_v1 import mobilenetv1

demonet = 'vgg16' dataset = 'pascal_voc' NETS = {'vgg16': ('vgg16.ckpt',)} DATASETS = {'pascal_voc': ('voc_2007_trainval',)} tfmodel = os.path.join('output', demonet, DATASETS[dataset][0], 'default', NETS[demonet][0])

def parse_args(): """ Parse input arguments """ parser = argparse.ArgumentParser(description='Test a Fast R-CNN network') parser.add_argument('--cfg', dest='cfg_file', help='optional config file', default=None, type=str) parser.add_argument('--model', dest='model', help='model to test', default=None, type=str) parser.add_argument('--imdb', dest='imdb_name', help='dataset to test', default='voc_2007_test', type=str) parser.add_argument('--comp', dest='comp_mode', help='competition mode', action='store_true') parser.add_argument('--num_dets', dest='max_per_image', help='max number of detections per image', default=100, type=int) parser.add_argument('--tag', dest='tag', help='tag of the model', default='', type=str)

parser.add_argument('--net', dest='net',

help='vgg16, res50, res101, res152, mobile',

default='res50', type=str)

parser.add_argument('--set', dest='set_cfgs', help='set config keys', default=None, nargs=argparse.REMAINDER) parser.add_argument('--net', dest='demo_net', help='Network to use [vgg16 res101]', choices=NETS.keys(), default='vgg16') parser.add_argument('--dataset', dest='dataset', help='Trained dataset [pascal_voc pascal_voc_0712]', choices=DATASETS.keys(), default='pascal_voc_0712')

if len(sys.argv) == 1:

parser.print_help()

sys.exit(1)

args = parser.parse_args() # 解析参数 return args

if name == 'main': args = parse_args()

print('Called with args:') print(args)

if args.cfg_file is not None:

cfg_from_file(args.cfg_file)

if args.set_cfgs is not None:

cfg_from_list(args.set_cfgs)

print('Using config:') pprint.pprint(cfg)

if has model, get the name from it

if does not, then just use the initialization weights

if tfmodel: filename = os.path.splitext(os.path.basename(tfmodel))[0] else: filename = os.path.splitext(os.path.basename(args.weight))[0]

tag = args.tag tag = tag if tag else 'default' filename = tag + '/' + filename

imdb = get_imdb(args.imdb_name) imdb.competition_mode(args.comp_mode)

tfconfig = tf.ConfigProto(allow_soft_placement=True) tfconfig.gpu_options.allow_growth=True

init session

sess = tf.Session(config=tfconfig)

load network

if demonet == 'vgg16': net = vgg16()

elif args.net == 'res50':

net = resnetv1(num_layers=50)

elif args.net == 'res101':

net = resnetv1(num_layers=101)

elif args.net == 'res152':

net = resnetv1(num_layers=152)

elif args.net == 'mobile':

net = mobilenetv1()

else: raise NotImplementedError

load model

net.create_architecture(sess, mode="TEST",num_classes=6, tag='default', anchor_scales=[8, 16, 32], anchor_ratios=[0.5, 1, 2])

if tfmodel: print(('Loading model check point from {:s}').format(tfmodel)) saver = tf.train.Saver() saver.restore(sess, tfmodel) print('Loaded.') else: print(('Loading initial weights from {:s}').format(args.weight)) sess.run(tf.global_variables_initializer()) print('Loaded.')

test_net(sess, net, imdb, filename, max_per_image=args.max_per_image)

sess.close()

I have solved the test problem,it can evaluate my own dataset under windows10 . Following next steps to evaluate your own dataset: First: make sure you can demo your own dataset Second:add following code to a new test_net.py Third:Input python test_net.py (the following code that i modified is not standard,i make this in order to evaluate AP and MAP.you can contact me If you have any questions)

--------------------------------------------------------

Tensorflow Faster R-CNN

Licensed under The MIT License [see LICENSE for details]

Written by Zheqi he, Xinlei Chen, based on code from Ross Girshick

--------------------------------------------------------

from future import absolute_import from future import division from future import print_function

import _init_paths

from lib.utils.test import test_net from lib.config import config as cfg

from lib.config import cfg, cfg_from_file, cfg_from_list

from lib.datasets.factory import get_imdb import argparse import pprint import time, os, sys

import tensorflow as tf from lib.nets.vgg16 import vgg16

from nets.resnet_v1 import resnetv1

from nets.mobilenet_v1 import mobilenetv1

demonet = 'vgg16' dataset = 'pascal_voc' NETS = {'vgg16': ('vgg16.ckpt',)} DATASETS = {'pascal_voc': ('voc_2007_trainval',)} tfmodel = os.path.join('output', demonet, DATASETS[dataset][0], 'default', NETS[demonet][0])

def parse_args(): """ Parse input arguments """ parser = argparse.ArgumentParser(description='Test a Fast R-CNN network') parser.add_argument('--cfg', dest='cfg_file', help='optional config file', default=None, type=str) parser.add_argument('--model', dest='model', help='model to test', default=None, type=str) parser.add_argument('--imdb', dest='imdb_name', help='dataset to test', default='voc_2007_test', type=str) parser.add_argument('--comp', dest='comp_mode', help='competition mode', action='store_true') parser.add_argument('--num_dets', dest='max_per_image', help='max number of detections per image', default=100, type=int) parser.add_argument('--tag', dest='tag', help='tag of the model', default='', type=str)

parser.add_argument('--net', dest='net',

help='vgg16, res50, res101, res152, mobile',

default='res50', type=str)

parser.add_argument('--set', dest='set_cfgs', help='set config keys', default=None, nargs=argparse.REMAINDER) parser.add_argument('--net', dest='demo_net', help='Network to use [vgg16 res101]', choices=NETS.keys(), default='vgg16') parser.add_argument('--dataset', dest='dataset', help='Trained dataset [pascal_voc pascal_voc_0712]', choices=DATASETS.keys(), default='pascal_voc_0712')

if len(sys.argv) == 1:

parser.print_help()

sys.exit(1)

args = parser.parse_args() # 解析参数 return args

if name == 'main': args = parse_args()

print('Called with args:') print(args)

if args.cfg_file is not None:

cfg_from_file(args.cfg_file)

if args.set_cfgs is not None:

cfg_from_list(args.set_cfgs)

print('Using config:') pprint.pprint(cfg)

if has model, get the name from it

if does not, then just use the initialization weights

if tfmodel: filename = os.path.splitext(os.path.basename(tfmodel))[0] else: filename = os.path.splitext(os.path.basename(args.weight))[0]

tag = args.tag tag = tag if tag else 'default' filename = tag + '/' + filename

imdb = get_imdb(args.imdb_name) imdb.competition_mode(args.comp_mode)

tfconfig = tf.ConfigProto(allow_soft_placement=True) tfconfig.gpu_options.allow_growth=True

init session

sess = tf.Session(config=tfconfig)

load network

if demonet == 'vgg16': net = vgg16()

elif args.net == 'res50':

net = resnetv1(num_layers=50)

elif args.net == 'res101':

net = resnetv1(num_layers=101)

elif args.net == 'res152':

net = resnetv1(num_layers=152)

elif args.net == 'mobile':

net = mobilenetv1()

else: raise NotImplementedError

load model

net.create_architecture(sess, mode="TEST",num_classes=6, tag='default', anchor_scales=[8, 16, 32], anchor_ratios=[0.5, 1, 2])

if tfmodel: print(('Loading model check point from {:s}').format(tfmodel)) saver = tf.train.Saver() saver.restore(sess, tfmodel) print('Loaded.') else: print(('Loading initial weights from {:s}').format(args.weight)) sess.run(tf.global_variables_initializer()) print('Loaded.')

test_net(sess, net, imdb, filename, max_per_image=args.max_per_image)

sess.close()

MsRabbits commented 5 years ago

Hi dude ,did you get the map after run this test_net file?

beibeiZ commented 5 years ago

dBeker这一版是不是没有输出log,怎么用tensorboard看训练

tutu8 commented 4 years ago

dBeker这一版是不是没有输出log,怎么用tensorboard看训练

Hello, have you found the solution to this problem?