Exemple #1
0
'''
After running this script, you'll be able to find the fetched images
in data/imagenet-images/<wnid>/
'''

import gflags
from gflags import FLAGS
from flags import set_gflags

from imagenet_image_fetcher import download_images

# This default wnid is for eggs
gflags.DEFINE_string('wnid', 'n07840804',
                     'The wordnet id of the noun in the positive images')

if __name__ == '__main__':
    set_gflags()
    download_images(FLAGS.wnid)
                       'annotated', basename(image_dir))
  if exists(annotated_dir):
    print 'The annotated dir for ' + video_id + ' already exists'
    return
  system('mkdir -p ' + annotated_dir)

  detections_filename = join('/tmp',
    '_'.join(['detection', 'results', FLAGS.model, wnid, video_id]) + '.bin')
  if not exists(detections_filename):
    print detections_filename, 'does not already exist'
    detect(image_dir, detections_filename,
           MODELS[FLAGS.model][0], MODELS[FLAGS.model][1])
  else:
    print detections_filename, 'already exists'
  if not exists(detections_filename):
    print 'Something went wrong during detection'
    sys.exit(1)
  draw_detection_results(detections_filename, annotated_dir)

def test_detector_on_eggs():
  # I choose 200 because we have 4 egg queries, and can fetch a maximum
  # of 50 search items (including playlists, channels and video-ids) per
  # query
  video_ids = get_egg_video_ids(200)
  for video_id in video_ids:
    draw_noun_detections_on_video_frames(video_id, 'n07840804')

if __name__ == '__main__':
  set_gflags()
  test_detector_on_eggs()