def classify_db_all(conf, db_file, model_files, model_type, name='deepnet', distort=False, return_hm=False, hm_dec=1, hm_floor=0.1, hm_nclustermax=1): cur_out = [] extra_str = '' if model_type not in ['leap', 'openpose']: extra_str = '.index' # else: # extra_str = '.h5' ts = [os.path.getmtime(f + extra_str) for f in model_files] for mndx, m in enumerate(model_files): # pred, label, gt_list = apt.classify_gt_data(conf, curm, out_file, m) tf_iterator = multiResData.tf_reader(conf, db_file, False) tf_iterator.batch_size = 1 read_fn = tf_iterator.next pred_fn, close_fn, _ = apt.get_pred_fn(model_type, conf, m, name=name, distort=distort) ret_list = apt.classify_db(conf, read_fn, pred_fn, tf_iterator.N, return_hm=return_hm, hm_dec=hm_dec, hm_floor=hm_floor, hm_nclustermax=hm_nclustermax) pred, label, gt_list = ret_list[:3] if model_type == 'mdn': extra_stuff = ret_list[3:] else: extra_stuff = 0 close_fn() gt_list = np.array(gt_list) cur_out.append([pred, label, gt_list, m, extra_stuff, ts[mndx]]) return cur_out
import deepcut.train conf = apt.create_conf(lbl_file,0,'test_openpose_delete') conf.splitType = 'predefined' apt.create_tfrecord(conf, True, split_file=split_file) from poseConfig import config as args args.skip_db = True apt.train_openpose(conf,args) ## import deepcut.train import tensorflow as tf tf.reset_default_graph conf.batch_size = 1 pred_fn, model_file = deepcut.train.get_pred_fn(conf) rfn, n= deepcut.train.get_read_fn(conf,'/home/mayank/work/poseTF/cache/apt_interface/multitarget_bubble_view0/test_deepcut/val_data.p') A = apt.classify_db(conf, rfn, pred_fn, n) ## import socket import APT_interface as apt import os import shutil import h5py import logging lbl_file = '/home/mayank/work/poseTF/data/alice/multitarget_bubble_expandedbehavior_20180425_local.lbl' conf = apt.create_conf(lbl_file,view=0,name='test_openpose') graph = [ [1,2],[1,3],[2,5],[3,4],[1,6],[6,7],[6,8],[6,10],[8,9],[10,11],[5,12],[9,13],[6,14],[6,15],[11,16],[4,17]] graph = [[g1-1, g2-1] for g1, g2 in graph] conf.op_affinity_graph = graph
def compute_peformance(args): H = h5py.File(args.lbl_file, 'r') nviews = int(apt.read_entry(H['cfg']['NumViews'])) dir_name = args.whose if len(args.nets) == 0: all_nets = methods else: all_nets = args.nets all_preds = {} for view in range(nviews): db_file = os.path.join(out_dir, args.name, args.gt_name) + '_view{}.tfrecords'.format(view) conf = apt.create_conf(args.lbl_file, view, name='a', net_type=all_nets[0], cache_dir=os.path.join(out_dir, args.name, dir_name)) conf.labelfile = args.gt_lbl if not (os.path.exists(db_file) and args.skip_gt_db): print('Creating GT DB file {}'.format(db_file)) apt.create_tfrecord(conf, split=False, on_gt=True, db_files=(db_file, )) for curm in all_nets: all_preds[curm] = [] for view in range(nviews): cur_out = [] db_file = os.path.join( out_dir, args.name, args.gt_name) + '_view{}.tfrecords'.format(view) if args.split_type is None: cachedir = os.path.join(out_dir, args.name, dir_name, '{}_view_{}'.format(curm, view), 'full') conf = apt.create_conf(args.lbl_file, view, name='a', net_type=curm, cache_dir=cachedir) model_files, ts = get_model_files(conf, cachedir, curm) for mndx, m in enumerate(model_files): out_file = m + '_' + args.gt_name load = False if curm == 'unet' or curm == 'deeplabcut': mm = m + '.index' else: mm = m if os.path.exists(out_file + '.mat') and os.path.getmtime( out_file + '.mat') > os.path.getmtime(mm): load = True if load: H = sio.loadmat(out_file) pred = H['pred_locs'] - 1 label = H['labeled_locs'] - 1 gt_list = H['list'] - 1 else: # pred, label, gt_list = apt.classify_gt_data(conf, curm, out_file, m) tf_iterator = multiResData.tf_reader( conf, db_file, False) tf_iterator.batch_size = 1 read_fn = tf_iterator.next pred_fn, close_fn, _ = apt.get_pred_fn(curm, conf, m) pred, label, gt_list = apt.classify_db( conf, read_fn, pred_fn, tf_iterator.N) close_fn() mat_pred_locs = pred + 1 mat_labeled_locs = np.array(label) + 1 mat_list = gt_list sio.savemat( out_file, { 'pred_locs': mat_pred_locs, 'labeled_locs': mat_labeled_locs, 'list': mat_list }) cur_out.append( [pred, label, gt_list, m, out_file, view, 0, ts[mndx]]) else: for cur_split in range(nsplits): cachedir = os.path.join(out_dir, args.name, '{}_view_{}'.format(curm, view), 'cv_{}'.format(cur_split)) conf = apt.create_conf(args.lbl_file, view, name='a', net_type=curm, cache_dir=cachedir) model_files, ts = get_model_files(conf, cachedir, curm) db_file = os.path.join(cachedir, 'val_TF.tfrecords') for mndx, m in enumerate(model_files): out_file = m + '.gt_data' load = False if curm == 'unet' or curm == 'deeplabcut': mm = m + '.index' else: mm = m if os.path.exists( out_file + '.mat') and os.path.getmtime( out_file + '.mat') > os.path.getmtime(mm): load = True if load: H = sio.loadmat(out_file) pred = H['pred_locs'] - 1 label = H['labeled_locs'] - 1 gt_list = H['list'] - 1 else: tf_iterator = multiResData.tf_reader( conf, db_file, False) tf_iterator.batch_size = 1 read_fn = tf_iterator.next pred_fn, close_fn, _ = apt.get_pred_fn( curm, conf, m) pred, label, gt_list = apt.classify_db( conf, read_fn, pred_fn, tf_iterator.N) close_fn() mat_pred_locs = pred + 1 mat_labeled_locs = np.array(label) + 1 mat_list = gt_list sio.savemat( out_file, { 'pred_locs': mat_pred_locs, 'labeled_locs': mat_labeled_locs, 'list': mat_list }) cur_out.append([ pred, label, gt_list, m, out_file, view, cur_split, ts[mndx] ]) all_preds[curm].append(cur_out) with open( os.path.join(out_dir, args.name, dir_name, args.gt_name + '_results.p'), 'w') as f: pickle.dump(all_preds, f)