def main(argv=None): # pylint: disable=unused-argument fd = face_detection_model(FLAGS.face_detection_type, FLAGS.face_detection_model) files = [] contains_faces = [] target = FLAGS.target = '%s.csv' % FLAGS.face_detection_type if FLAGS.target is None else FLAGS.target print('Creating output file %s' % target) output = open(target, 'w') writer = csv.writer(output) writer.writerow(('file_with_face', )) if FLAGS.filename is not None: if os.path.isdir(FLAGS.filename): for relpath in os.listdir(FLAGS.filename): abspath = os.path.join(FLAGS.filename, relpath) if os.path.isfile(abspath) and any([ abspath.endswith('.' + ty) for ty in ('jpg', 'png', 'JPG', 'PNG', 'jpeg') ]): print(abspath) files.append(abspath) elif any([ FLAGS.filename.endswith('.' + ty) for ty in ('csv', 'tsv', 'txt') ]): files = list_images(FLAGS.filename) else: files = [FLAGS.filename] for f in files: try: images, outfile = fd.run(f) if len(images): print(f, 'YES') writer.writerow((f, )) contains_faces.append(f) else: print(f, 'NO') except Exception as e: print(e)
def main(argv=None): # pylint: disable=unused-argument files = [] if FLAGS.face_detection_model: print('Using face detector (%s) %s' % (FLAGS.face_detection_type, FLAGS.face_detection_model)) face_detect = face_detection_model(FLAGS.face_detection_type, FLAGS.face_detection_model) face_files, rectangles = face_detect.run(FLAGS.filename) print(face_files) files += face_files with tf.Session() as sess: #tf.reset_default_graph() label_list = AGE_LIST if FLAGS.class_type == 'age' else GENDER_LIST nlabels = len(label_list) print('Executing on %s' % FLAGS.device_id) model_fn = select_model(FLAGS.model_type) with tf.device(FLAGS.device_id): images = tf.placeholder(tf.float32, [None, RESIZE_FINAL, RESIZE_FINAL, 3]) logits = model_fn(nlabels, images, 1, False) init = tf.global_variables_initializer() requested_step = FLAGS.requested_step if FLAGS.requested_step else None checkpoint_path = '%s' % (FLAGS.model_dir) model_checkpoint_path, global_step = get_checkpoint( checkpoint_path, requested_step, FLAGS.checkpoint) saver = tf.train.Saver() saver.restore(sess, model_checkpoint_path) softmax_output = tf.nn.softmax(logits) coder = ImageCoder() # Support a batch mode if no face detection model if len(files) == 0: files.append(FLAGS.filename) # If it happens to be a list file, read the list and clobber the files if one_of(FLAGS.filename, ('csv', 'tsv', 'txt')): files = batchlist(FLAGS.filename) writer = None output = None if FLAGS.target: print('Creating output file %s' % FLAGS.target) output = open(FLAGS.target, 'w') writer = csv.writer(output) writer.writerow(('file', 'label', 'score')) for f in files: image_file = resolve_file(f) if image_file is None: continue try: best_choice = classify(sess, label_list, softmax_output, coder, images, image_file) if writer is not None: writer.writerow( (f, best_choice[0], '%.2f' % best_choice[1])) except Exception as e: print(e) print('Failed to run image %s ' % image_file) if output is not None: output.close()
def main(argv=None): # pylint: disable=unused-argument files = [] if FLAGS.face_detection_model: print('Using face detector (%s) %s' % (FLAGS.face_detection_type, FLAGS.face_detection_model)) face_detect = face_detection_model(FLAGS.face_detection_type, FLAGS.face_detection_model) face_files, rectangles = face_detect.run(FLAGS.filename) print(face_files) files += face_files with tf.Session() as sess: #tf.reset_default_graph() label_list = AGE_LIST if FLAGS.class_type == 'age' else GENDER_LIST nlabels = len(label_list) print('Executing on %s' % FLAGS.device_id) model_fn = select_model(FLAGS.model_type) with tf.device(FLAGS.device_id): images = tf.placeholder(tf.float32, [None, RESIZE_FINAL, RESIZE_FINAL, 3]) logits = model_fn(nlabels, images, 1, False) init = tf.global_variables_initializer() requested_step = FLAGS.requested_step if FLAGS.requested_step else None checkpoint_path = '%s' % (FLAGS.model_dir) model_checkpoint_path, global_step = get_checkpoint(checkpoint_path, requested_step, FLAGS.checkpoint) saver = tf.train.Saver() saver.restore(sess, model_checkpoint_path) softmax_output = tf.nn.softmax(logits) coder = ImageCoder() # Support a batch mode if no face detection model if len(files) == 0: files.append(FLAGS.filename) # If it happens to be a list file, read the list and clobber the files if one_of(FLAGS.filename, ('csv', 'tsv', 'txt')): files = batchlist(FLAGS.filename) writer = None output = None if FLAGS.target: print('Creating output file %s' % FLAGS.target) output = open(FLAGS.target, 'w') writer = csv.writer(output) writer.writerow(('file', 'label', 'score')) for f in files: image_file = resolve_file(f) if image_file is None: continue try: best_choice = classify(sess, label_list, softmax_output, coder, images, image_file) if writer is not None: writer.writerow((f, best_choice[0], '%.2f' % best_choice[1])) except Exception as e: print(e) print('Failed to run image %s ' % image_file) if output is not None: output.close()
def main(argv=None): # pylint: disable=unused-argument files = [] if FLAGS.face_detection_model: print('Using face detector (%s) %s' % (FLAGS.face_detection_type, FLAGS.face_detection_model)) face_detect = face_detection_model(FLAGS.face_detection_type, FLAGS.face_detection_model) face_files, rectangles = face_detect.run(FLAGS.filename) print(face_files) files += face_files config = tf.ConfigProto(allow_soft_placement=True) with tf.Session(config=config) as sess: label_list = AGE_LIST if FLAGS.class_type == 'age' else GENDER_LIST nlabels = len(label_list) print('Executing on %s' % FLAGS.device_id) model_fn = select_model(FLAGS.model_type) with tf.device(FLAGS.device_id): images = tf.placeholder(tf.float32, [None, RESIZE_FINAL, RESIZE_FINAL, 3]) logits = model_fn(nlabels, images, 1, False) init = tf.global_variables_initializer() requested_step = FLAGS.requested_step if FLAGS.requested_step else None checkpoint_path = '%s' % (FLAGS.model_dir) model_checkpoint_path, global_step = get_checkpoint( checkpoint_path, requested_step, FLAGS.checkpoint) saver = tf.train.Saver() saver.restore(sess, model_checkpoint_path) softmax_output = tf.nn.softmax(logits) coder = ImageCoder() # Support a batch mode if no face detection model if len(files) == 0: if (os.path.isdir(FLAGS.filename)): for relpath in os.listdir(FLAGS.filename): abspath = os.path.join(FLAGS.filename, relpath) if os.path.isfile(abspath) and any([ abspath.endswith('.' + ty) for ty in ('jpg', 'png', 'JPG', 'PNG', 'jpeg') ]): print(abspath) files.append(abspath) else: files.append(FLAGS.filename) # If it happens to be a list file, read the list and clobber the files if any([ FLAGS.filename.endswith('.' + ty) for ty in ('csv', 'tsv', 'txt') ]): files = list_images(FLAGS.filename) writer = None output = None if FLAGS.target: print('Creating output file %s' % FLAGS.target) output = open(FLAGS.target, 'w') writer = csv.writer(output) writer.writerow(('file', 'label', 'score')) image_files = list( filter(lambda x: x is not None, [resolve_file(f) for f in files])) print(image_files) if FLAGS.single_look: classify_many_single_crop(sess, label_list, softmax_output, coder, images, image_files, writer) else: for image_file in image_files: classify_one_multi_crop(sess, label_list, softmax_output, coder, images, image_file, writer) if output is not None: output.close()