当前位置: 首页>>代码示例>>Python>>正文


Python PoseTools.get_base_pred_locs方法代码示例

本文整理汇总了Python中PoseTools.get_base_pred_locs方法的典型用法代码示例。如果您正苦于以下问题:Python PoseTools.get_base_pred_locs方法的具体用法?Python PoseTools.get_base_pred_locs怎么用?Python PoseTools.get_base_pred_locs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PoseTools的用法示例。


在下文中一共展示了PoseTools.get_base_pred_locs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: prepareOpt

# 需要导入模块: import PoseTools [as 别名]
# 或者: from PoseTools import get_base_pred_locs [as 别名]
def prepareOpt(baseNet,l8,dbtype,feed_dict,sess,conf,phDict,distort,nsamples=10):
    baseNet.updateFeedDict(dbtype,distort)
    locs = baseNet.locs
    bout = sess.run(l8,feed_dict=baseNet.feed_dict)
    predlocs = PoseTools.get_base_pred_locs(bout, conf)
    
    #repeat locs nsamples times
    ls = locs.shape
    locs = np.tile(locs[:,np.newaxis,:,:],[1,nsamples,1,1])
    locs = np.reshape(locs,[ls[0]*nsamples,ls[1],ls[2]])
    predlocs = np.tile(predlocs[:,np.newaxis,:,:],[1,nsamples,1,1])
    predlocs = np.reshape(predlocs,[ls[0]*nsamples,ls[1],ls[2]])
    
    newlocs = genLocs(locs,predlocs,conf)
    new_mean = newlocs.mean(axis=1)
    
    locs_mean = locs.mean(axis=1)
    dlocs = locs-locs_mean[:,np.newaxis,:]
    newlocs = newlocs-new_mean[:,np.newaxis,:]
    
    d_mean = locs_mean-new_mean
    
    scores = np.zeros(locs.shape[0:2])
    scale = conf.rescale*conf.pool_scale
    rlocs = (np.round(old_div(newlocs,scale))).astype('int')
    for ndx in range(predlocs.shape[0]):
        for cls in range(conf.n_classes):
            bndx = int(math.floor(old_div(ndx,nsamples)))
            scores[ndx,cls] = bout[bndx,rlocs[ndx,cls,1],rlocs[ndx,cls,0],cls]

    feed_dict[phDict['y']] = np.reshape(dlocs,[-1,2*conf.n_classes])
    feed_dict[phDict['y_m']] = d_mean
    feed_dict[phDict['scores']] = scores
    feed_dict[phDict['locs']] = newlocs
    return new_mean, locs_mean
开发者ID:mkabra,项目名称:poseTF,代码行数:37,代码来源:poseGen.py

示例2: open

# 需要导入模块: import PoseTools [as 别名]
# 或者: from PoseTools import get_base_pred_locs [as 别名]
self.feed_dict[self.ph['base_locs']] = np.zeros([self.conf.batch_size,
                                                 self.conf.n_classes, 2])
sess.run(tf.global_variables_initializer())

with open(os.path.join(conf.cachedir, 'base_predictions'),
          'rb') as f:
    train_data, test_data = pickle.load(f)

m_train_data = train_data
o_test_data = copy.deepcopy(test_data)
for ndx in range(len(test_data)):
    bpred_in = test_data[ndx][0]
    tr_ndx = np.random.choice(len(train_data))
    bpred_tr = train_data[tr_ndx][0]
    bpred_out = -1 * np.ones(bpred_in.shape)
    tr_locs = PoseTools.get_base_pred_locs(bpred_tr, self.conf) / 4
    in_locs = PoseTools.get_base_pred_locs(bpred_in, self.conf) / 4

    # test blobs training locs
    for ex in range(bpred_in.shape[0]):
        for cls in range(bpred_in.shape[-1]):
            cur_sc = bpred_in[ex,:,:,cls]
            inxx = int(in_locs[ex,cls,0])
            inyy = int(in_locs[ex,cls,1])
            trxx = int(tr_locs[ex,cls,0])
            tryy = int(tr_locs[ex,cls,1])
            test_sc = bpred_in[ex,(inyy-10):(inyy+10),
                    (inxx - 10):(inxx + 10),cls]
            bpred_out[ex,(tryy-10):(tryy+10),
                (trxx - 10):(trxx + 10),cls ] = test_sc
    test_data[ndx][0] = bpred_out
开发者ID:mkabra,项目名称:poseTF,代码行数:33,代码来源:script_offline_MDN_joint.py

示例3: print

# 需要导入模块: import PoseTools [as 别名]
# 或者: from PoseTools import get_base_pred_locs [as 别名]
mod_t = np.array(mod_tt).reshape([-1, 5])
mod_w = np.array([i[0] for i in mod_preds]).reshape([-1, 256])
mod_rw = np.array([i[5] for i in mod_preds]).reshape([-1, 256])
mod_m = np.array([i[1] for i in mod_preds]).reshape([-1, 256, 5, 2])
mod_s = np.array([i[2] for i in mod_preds]).reshape([-1, 256, 5])
mod_l = np.array(mod_locs).reshape([-1, 5, 2])
mod_loss = np.array([i[4] for i in mod_preds]).reshape([-1, 5])
mod_lm = (mod_l / 4) % 16
mod_x = np.array(mod_x).reshape([-1, 512, 512])
mod_bpred = np.array(mod_bpred).reshape([-1, 128, 128, 5])
gg = PoseTools.get_base_error(mod_l, mod_bpred, conf)
mod_ot = np.sqrt(np.sum(gg**2,2))

print(np.argmax(mod_t,axis=0))
print(np.max(mod_t,axis=0))
blocs = PoseTools.get_base_pred_locs(mod_bpred, conf)
sc = -1
##
sc += 1
kk = np.flipud(np.argsort(mod_t.flatten()))
[yy,xx] = np.unravel_index(kk[:30],mod_t.shape)
# kk = np.argsort(mod_t.sum(axis=1))
# yy = kk[:10]
print(np.unique(yy))

sel = np.unique(yy)[sc]
print(mod_t[sel,:])

f = plt.figure(figsize=[12,12])
ax = f.add_subplot(111)
plt.imshow(mod_x[sel,:,:],cmap='gray')
开发者ID:mkabra,项目名称:poseTF,代码行数:33,代码来源:debugMDN.py

示例4: range

# 需要导入模块: import PoseTools [as 别名]
# 或者: from PoseTools import get_base_pred_locs [as 别名]
val_l7 = np.zeros([numex,conf.nfcfilt,conf.n_classes])

numtr = self.env.stat()['entries']
tr_preds = np.zeros([numtr,]+self.basePred.get_shape().as_list()[1:]+[2,])
tr_maxsc = np.zeros([numtr,conf.n_classes])
tr_ims = np.zeros((numtr,)+conf.imsz)
tr_pred_locs = np.zeros([numtr,conf.n_classes,2,2])
tr_l7 = np.zeros([numtr,conf.nfcfilt,conf.n_classes])

self.val_cursor.first()
for count in range(numex):
    self.updateFeedDict(self.DBType.Val)
    curpred = sess.run([self.basePred,self.baseLayers['conv7']],feed_dict = self.feed_dict)
    val_preds[count,:,:,:,0] = curpred[0]
    val_maxsc[count,:] = curpred[0][0,:,:,:].max(axis=1).max(axis=0)
    curlocs = PoseTools.get_base_pred_locs(curpred[0], conf)[0, :, :]
    val_pred_locs[count,:,:,0] = curlocs
    val_pred_locs[count,:,:,1] = self.locs[0,:,:]
    val_ims[count,:,:] = self.xs[0,0,:,:]
    for ndx in range(conf.n_classes):
        curx = int(curlocs[ndx,0]/conf.pool_scale/conf.rescale)
        cury = int(curlocs[ndx,1]/conf.pool_scale/conf.rescale)
        val_l7[count,:,ndx] = curpred[1][0,cury,curx,:]
 

                       
self.train_cursor.first()
for count in range(numtr):
    self.updateFeedDict(self.DBType.Train)
    curpred = sess.run([self.basePred,self.baseLayers['conv7']],feed_dict = self.feed_dict)
    tr_preds[count,:,:,:,0] = curpred[0]
开发者ID:mkabra,项目名称:poseTF,代码行数:33,代码来源:janLegCell.py

示例5: train

# 需要导入模块: import PoseTools [as 别名]
# 或者: from PoseTools import get_base_pred_locs [as 别名]
def train(conf,restore=True):
    
    phDict = createEvalPH(conf)
    feed_dict = createFeedDict(phDict)
    feed_dict[phDict['phase_train']] = True
    feed_dict[phDict['dropout']] = 0.5
    with tf.variable_scope('poseEval'):
        out,layer_dict = poseEvalNet(phDict['lin'],phDict['locs'],
                                     conf,phDict['phase_train'],
                                     phDict['dropout'])
        
    evalSaver = createEvalSaver(conf)
    y = phDict['y']
    cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(out, y))
    train_step = tf.train.AdamOptimizer(1e-5).minimize(cross_entropy)
    correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(out,1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
    baseNet = PoseTools.create_network(conf, 1)
    baseNet.openDBs()
    
    with baseNet.env.begin() as txn,baseNet.valenv.begin() as valtxn,tf.Session() as sess:

        baseNet.createCursors()
        baseNet.restoreBase(sess,True)
        didRestore,startat = restoreEval(sess,conf,evalSaver,restore)
        baseNet.initializeRemainingVars(sess)
        for step in range(startat,conf.eval_training_iters+1):
            prepareOpt(baseNet,baseNet.DBType.Train,feed_dict,sess,conf,
                       phDict,distort=True)
#             baseNet.feed_dict[baseNet.ph['keep_prob']] = 0.5
            feed_dict[phDict['phase_train']] = True
            feed_dict[phDict['dropout']] = 0.5
            sess.run(train_step, feed_dict=feed_dict)

            if step % 25 == 0:
                prepareOpt(baseNet,baseNet.DBType.Train,feed_dict,
                           sess,conf,phDict,distort=False)
#                 baseNet.feed_dict[baseNet.ph['keep_prob']] = 1
                feed_dict[phDict['phase_train']] = False
                feed_dict[phDict['dropout']] = 1
                train_cross_ent = sess.run(cross_entropy, feed_dict=feed_dict)
                test_cross_ent = 0
                test_acc = 0
                pos_acc = 0
                pred_acc_pos = 0
                pred_acc_pred = 0
                
                #generate blocks for different neg types
                nsamples = 10
                ntypes = 3
                npos = 2
                blk = np.arange(nsamples)
                inter = np.arange(0,conf.batch_size*nsamples*(ntypes+npos),nsamples*(ntypes+npos))
                n_inters = blk + inter[:,np.newaxis]
                n_inters = n_inters.flatten()
                nacc = np.zeros(ntypes)
                nclose = 0 
                in_locs = np.array([])
                nrep = 40
                for rep in range(nrep):
                    prepareOpt(baseNet,baseNet.DBType.Val,feed_dict,sess,conf,
                               phDict,distort=False)
                    test_cross_ent += sess.run(cross_entropy, feed_dict=feed_dict)
                    test_acc += sess.run(accuracy, feed_dict = feed_dict)
                    tout = sess.run(correct_prediction, feed_dict=feed_dict)
                    labels = feed_dict[phDict['y']]
                    pos_acc += old_div(float(np.count_nonzero(tout[labels[:,1]>0.5])),nsamples)
                    for nt in range(ntypes):
                        nacc[nt] += old_div(float(np.count_nonzero(tout[n_inters+nt*nsamples])),nsamples)
                    
                    tdd = feed_dict[phDict['lin']]
                    tlocs = feed_dict[phDict['locs']]
                    ty = feed_dict[phDict['y']]
                    # 
                    l7 = baseNet.baseLayers['conv7']
                    curpred = sess.run([baseNet.basePred,l7], feed_dict=baseNet.feed_dict)
                    baseLocs = PoseTools.get_base_pred_locs(curpred[0], conf)

                    neglocs = baseLocs[:,:,:,np.newaxis]
                    locs = np.array(baseNet.locs)[...,np.newaxis]
                    d2locs = np.sqrt( np.sum((neglocs-locs)**2,axis=(1,2,3)))
                    alllocs = np.concatenate([neglocs,locs],axis=3)
                    alldd = genData(curpred[1],alllocs,conf)
                    alllocs = alllocs.transpose([0,3,1,2])
                    alllocs = alllocs.reshape((-1,)+alllocs.shape[2:])
                    alllocs_m = alllocs.mean(1)
                    alllocs = alllocs-alllocs_m[:,np.newaxis,:]

                    alldd = alldd.transpose([0,3,1,2])
                    alldd = np.reshape(alldd,[-1,alldd.shape[-2],alldd.shape[-1]])

                    y = np.zeros([curpred[0].shape[0],alllocs.shape[-1],2])
                    y[d2locs>=25,:-1,0] = 1. 
                    y[d2locs<25,:-1,1] = 1. 
                    y[:,-1,1] = 1.
                    y = np.reshape(y,[-1,y.shape[-1]])

                    feed_dict[phDict['y']] = y
                    feed_dict[phDict['lin']] = alldd
                    feed_dict[phDict['locs']] = alllocs
#.........这里部分代码省略.........
开发者ID:mkabra,项目名称:poseTF,代码行数:103,代码来源:poseEval.py


注:本文中的PoseTools.get_base_pred_locs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。