def get_network(type, placeholder_input, sess_for_load=None, trainable=True): if type == 'mobilenet': net = MobilenetNetwork({'image': placeholder_input}, conv_width=0.75, conv_width2=1.00, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_fast': net = MobilenetNetwork({'image': placeholder_input}, conv_width=0.5, conv_width2=0.5, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_accurate': net = MobilenetNetwork({'image': placeholder_input}, conv_width=1.00, conv_width2=1.00, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_thin': net = MobilenetNetworkThin({'image': placeholder_input}, conv_width=0.75, conv_width2=0.50, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_1.0_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'cmu': net = CmuNetwork({'image': placeholder_input}, trainable=trainable) pretrain_path = 'numpy/openpose_coco.npy' last_layer = 'Mconv7_stage6_L{aux}' elif type == 'vgg': net = CmuNetwork({'image': placeholder_input}, trainable=trainable) pretrain_path = 'numpy/openpose_vgg16.npy' last_layer = 'Mconv7_stage6_L{aux}' else: raise Exception('Invalid Mode.') if sess_for_load is not None: if type == 'cmu' or type == 'vgg': net.load(os.path.join(_get_base_path(), pretrain_path), sess_for_load) else: s = '%dx%d' % (placeholder_input.shape[2], placeholder_input.shape[1]) ckpts = { 'mobilenet': 'trained/mobilenet_%s/model-246038' % s, 'mobilenet_thin': 'trained/mobilenet_thin_%s/model-449003' % s, 'mobilenet_fast': 'trained/mobilenet_fast_%s/model-189000' % s, 'mobilenet_accurate': 'trained/mobilenet_accurate/model-170000' } loader = tf.train.Saver() loader.restore(sess_for_load, os.path.join(_get_base_path(), ckpts[type])) return net, os.path.join(_get_base_path(), pretrain_path), last_layer
def get_network(type, placeholder_input, sess_for_load=None): if type == 'mobilenet': net = MobilenetNetwork({'image': placeholder_input}, conv_width=0.75, conv_width2=0.50) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_accurate': net = MobilenetNetwork({'image': placeholder_input}, conv_width=1.00) pretrain_path = 'pretrained/mobilenet_v1_1.0_224_2017_06_14/mobilenet_v1_1.0_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_fast': net = MobilenetNetwork({'image': placeholder_input}, conv_width=0.50) pretrain_path = 'pretrained/mobilenet_v1_0.50_224_2017_06_14/mobilenet_v1_0.50_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'cmu': net = CmuNetwork({'image': placeholder_input}) pretrain_path = 'numpy/openpose_coco.npy' last_layer = 'Mconv7_stage6_L{aux}' else: raise Exception('Invalid Mode.') if sess_for_load is not None: if type == 'cmu': net.load('./models/numpy/openpose_coco.npy', sess_for_load) else: ckpts = { 'mobilenet': os.path.join(_get_base_path(), 'pretrained/mobilenet_v1_0.50_224_2017_06_14/mobilenet_v1_0.50_224.ckpt'), 'mobilenet_fast': os.path.join(_get_base_path(), 'pretrained/mobilenet_fast/-163000'), 'mobilenet_accurate': os.path.join(_get_base_path(), 'pretrained/mobilenet_accurate/model-170000') } # loader = tf.train.import_meta_graph(ckpts[type] + '.meta') loader = tf.train.Saver() loader.restore(sess_for_load, ckpts[type]) return net, os.path.join(_get_base_path(), pretrain_path), last_layer
default='cmu', help='cmu / dsconv / mobilenet') args = parser.parse_args() input_node = tf.placeholder(tf.float32, shape=(None, args.input_height, args.input_width, 3), name='image') with tf.Session(config=config) as sess: if args.model == 'dsconv': net = DSConvNetwork({'image': input_node}, trainable=False) net.load('./models/numpy/fastopenpose_coco_v170729.npy', sess) last_layer = 'Mconv7_stage{stage}_L{aux}' elif args.model == 'cmu': net = CmuNetwork({'image': input_node}, trainable=False) net.load('./models/numpy/openpose_coco.npy', sess) last_layer = 'Mconv7_stage{stage}_L{aux}' elif args.model == 'mobilenet_1.0': net = MobilenetNetwork({'image': input_node}, trainable=False, conv_width=1.0) sess.run(tf.global_variables_initializer()) # TODO last_layer = 'MConv_Stage{stage}_L{aux}_5' elif args.model == 'mobilenet_0.50': net = MobilenetNetwork({'image': input_node}, trainable=False, conv_width=0.50) sess.run(tf.global_variables_initializer()) # TODO last_layer = 'MConv_Stage{stage}_L{aux}_5' else:
def get_network(type, placeholder_input, sess_for_load=None, trainable=True): if type == 'mobilenet': net = MobilenetNetwork({'image': placeholder_input}, conv_width=0.75, conv_width2=1.00, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_fast': net = MobilenetNetwork({'image': placeholder_input}, conv_width=0.5, conv_width2=0.5, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_accurate': net = MobilenetNetwork({'image': placeholder_input}, conv_width=1.00, conv_width2=1.00, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_1.0_224_2017_06_14/mobilenet_v1_1.0_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_thin': net = MobilenetNetworkThin({'image': placeholder_input}, conv_width=0.75, conv_width2=0.50, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'cmu': net = CmuNetwork({'image': placeholder_input}, trainable=trainable) pretrain_path = 'numpy/openpose_coco.npy' last_layer = 'Mconv7_stage6_L{aux}' elif type == 'vgg': net = CmuNetwork({'image': placeholder_input}, trainable=trainable) pretrain_path = 'numpy/openpose_vgg16.npy' last_layer = 'Mconv7_stage6_L{aux}' elif type == 'personlab_resnet101': net = PersonLabNetwork({'image': placeholder_input}, trainable=trainable) pretrain_path = 'pretrained/resnet_v2_101/resnet_v2_101.ckpt' last_layer = 'Mconv7_stage6_L{aux}' else: raise Exception('Invalid Mode.') pretrain_path_full = os.path.join(_get_base_path(), pretrain_path) if sess_for_load is not None: if type == 'cmu' or type == 'vgg': if not os.path.isfile(pretrain_path_full): raise Exception('Model file doesn\'t exist, path=%s' % pretrain_path_full) net.load(os.path.join(_get_base_path(), pretrain_path), sess_for_load) else: s = '%dx%d' % (placeholder_input.shape[2], placeholder_input.shape[1]) ckpts = { 'mobilenet': 'trained/mobilenet_%s/model-246038' % s, 'mobilenet_thin': 'trained/mobilenet_thin_%s/model-449003' % s, 'mobilenet_fast': 'trained/mobilenet_fast_%s/model-189000' % s, 'mobilenet_accurate': 'trained/mobilenet_accurate/model-170000' } ckpt_path = os.path.join(_get_base_path(), ckpts[type]) loader = tf.train.Saver() try: loader.restore(sess_for_load, ckpt_path) except Exception as e: raise Exception('Fail to load model files. \npath=%s\nerr=%s' % (ckpt_path, str(e))) return net, pretrain_path_full, last_layer
net = MobilenetNetwork({'image': q_inp_split[gpu_id]}, conv_width=1.0) pretrain_path = './models/pretrained/mobilenet_v1_1.0_224_2017_06_14/mobilenet_v1_1.0_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif args.model == 'mobilenet_0.75': net = MobilenetNetwork({'image': q_inp_split[gpu_id]}, conv_width=0.75) pretrain_path = './models/pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif args.model == 'mobilenet_0.50': net = MobilenetNetwork({'image': q_inp_split[gpu_id]}, conv_width=0.50) pretrain_path = './models/pretrained/mobilenet_v1_0.50_224_2017_06_14/mobilenet_v1_0.50_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif args.model == 'cmu': net = CmuNetwork({'image': q_inp_split[gpu_id]}) pretrain_path = './models/numpy/openpose_coco.npy' last_layer = 'Mconv7_stage6_L{aux}' elif args.model == 'mobilenet_p_1.0': from network_mobilenet3 import MobilenetNetwork net = MobilenetNetwork({'image': q_inp_split[gpu_id]}, conv_width=1.0) pretrain_path = './models/pretrained/mobilenet_v1_1.0_224_2017_06_14/mobilenet_v1_1.0_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif args.model == 'mobilenet_p_0.50': from network_mobilenet3 import MobilenetNetwork net = MobilenetNetwork({'image': q_inp_split[gpu_id]}, conv_width=0.50) pretrain_path = './models/pretrained/mobilenet_v1_0.50_224_2017_06_14/mobilenet_v1_0.50_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' else:
def get_network(type, placeholder_input, sess_for_load=None, trainable=True): if type == 'mobilenet': net = MobilenetNetwork({'image': placeholder_input}, conv_width=0.75, conv_width2=1.00, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_fast': net = MobilenetNetworkFast({'image': placeholder_input}, conv_width=0.5, conv_width2=0.5, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.50_224_2017_06_14/mobilenet_v1_0.50_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_accurate': net = MobilenetNetworkThin({'image': placeholder_input}, conv_width=1.00, conv_width2=0.50, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_1.0_224_2017_06_14/mobilenet_v1_1.0_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_thin': net = MobilenetNetworkThin({'image': placeholder_input}, conv_width=0.75, conv_width2=0.750, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_original': net = MobilenetNetworkOriginal({'image': placeholder_input}, conv_width=0.75, conv_width2=0.50, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v1_0.75_224_2017_06_14/mobilenet_v1_0.75_224.ckpt' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'mobilenet_v2': net = MobilenetNetworkV2({'image': placeholder_input}, conv_width=1, conv_width2=0.50, trainable=trainable) pretrain_path = 'pretrained/mobilenet_v2/model.ckpt-1450000' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'cmu': net = CmuNetwork({'image': placeholder_input}, trainable=trainable) pretrain_path = 'numpy/openpose_coco.npy' last_layer = 'Mconv7_stage6_L{aux}' elif type == 'vgg': net = CmuNetwork({'image': placeholder_input}, trainable=trainable) pretrain_path = 'numpy/openpose_coco.npy' last_layer = 'Mconv7_stage6_L{aux}' elif type == 'resnet32': net = Resnet32({'image': placeholder_input}, conv_width=0.75, conv_width2=0.50, trainable=trainable) pretrain_path = 'numpy/resnet32.npy' last_layer = 'MConv_Stage6_L{aux}_5' elif type == 'vgg16x4': net = VGG16x4Network({'image': placeholder_input}, conv_width=0.75, conv_width2=0.75, trainable=trainable) pretrain_path = 'numpy/vgg16x4.npy' last_layer = 'Mconv7_stage6_L{aux}' else: raise Exception('Invalid Mode.') if sess_for_load is not None: if type == 'cmu' or type == 'vgg': net.load(os.path.join(_get_base_path(), pretrain_path), sess_for_load) else: s = '%dx%d' % (placeholder_input.shape[2], placeholder_input.shape[1]) ckpts = { 'mobilenet': 'models/trained/mobilenet_%s/model-53008' % s, 'mobilenet_thin': 'models/trained/mobilenet_thin_432x368/model-160001', 'mobilenet_original': 'models/trained/mobilenet_thin_benchmark/model-388003', 'mobilenet_v2': 'models/trained/mobilenet_v2/model-218000', 'vgg16x4': 'models/trained/vgg16x4_0.75/model-35000', } loader = tf.train.Saver() loader.restore(sess_for_load, os.path.join(base_path, ckpts[type])) return net, os.path.join(_get_base_path(), pretrain_path), last_layer