def calc_flops(model): # manually build the graph with batch=1 input_desc = [ InputDesc(tf.float32, [1, 224, 224, 3], 'input'), InputDesc(tf.int32, [1], 'label') ] input = PlaceholderInput() input.setup(input_desc) with TowerContext('', is_training=False): model.build_graph(*input.get_input_tensors()) model_utils.describe_trainable_vars() tf.profiler.profile( tf.get_default_graph(), cmd='op', options=tf.profiler.ProfileOptionBuilder.float_operation()) logger.info( "Note that TensorFlow counts flops in a different way from the paper.") logger.info( "TensorFlow counts multiply+add as two flops, however the paper counts them " "as 1 flop because it can be executed in one instruction.")
if args.eval: batch = 128 # something that can run on one gpu ds = get_data('val', batch) eval_on_ILSVRC12(model, get_model_loader(args.load), ds) elif args.flops: # manually build the graph with batch=1 input_desc = [ InputDesc(tf.float32, [1, 224, 224, 3], 'input'), InputDesc(tf.int32, [1], 'label') ] input = PlaceholderInput() input.setup(input_desc) with TowerContext('', is_training=False): model.build_graph(*input.get_input_tensors()) model_utils.describe_trainable_vars() tf.profiler.profile( tf.get_default_graph(), cmd='op', options=tf.profiler.ProfileOptionBuilder.float_operation()) logger.info("Note that TensorFlow counts flops in a different way from the paper.") logger.info("TensorFlow counts multiply+add as two flops, however the paper counts them " "as 1 flop because it can be executed in one instruction.") else: if args.v2: name = "ShuffleNetV2-{}x".format(args.ratio) else: name = "ShuffleNetV1-{}x-g{}".format(args.ratio, args.group) logger.set_logger_dir(os.path.join('train_log', name))
TOTAL_BATCH_SIZE = args.batch model = Model() if args.eval: batch = 128 # something that can run on one gpu ds = get_data('val', batch) eval_classification(model, SmartInit(args.load), ds) elif args.flops: # manually build the graph with batch=1 with TowerContext('', is_training=False): model.build_graph( tf.placeholder(tf.float32, [1, 224, 224, 3], 'input'), tf.placeholder(tf.int32, [1], 'label') ) model_utils.describe_trainable_vars() tf.profiler.profile( tf.get_default_graph(), cmd='op', options=tf.profiler.ProfileOptionBuilder.float_operation()) logger.info("Note that TensorFlow counts flops in a different way from the paper.") logger.info("TensorFlow counts multiply+add as two flops, however the paper counts them " "as 1 flop because it can be executed in one instruction.") else: if args.v2: name = "ShuffleNetV2-{}x".format(args.ratio) else: name = "ShuffleNetV1-{}x-g{}".format(args.ratio, args.group) logger.set_logger_dir(os.path.join('train_log', name))
def after_create_session(self, session, cord): describe_trainable_vars()