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


Python COCOScorer.score方法代码示例

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


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

示例1: test

# 需要导入模块: from cocoeval import COCOScorer [as 别名]
# 或者: from cocoeval.COCOScorer import score [as 别名]
def test(model_path='models/model-900', video_feat_path=video_feat_path):
    meta_data, train_data, test_data = get_video_data_jukin(video_data_path_train, video_data_path_test)
    #test_data = train_data
    ixtoword = pd.Series(np.load('./data/ixtoword.npy').tolist())

    model = Video_Caption_Generator(
            dim_image=dim_image,
            n_words=len(ixtoword),
            dim_hidden=dim_hidden,
            batch_size=batch_size,
            n_lstm_steps=n_frame_step,
	    drop_out_rate = 0,
            bias_init_vector=None)

    video_tf, video_mask_tf, video_len_tf, HLness_tf, caption_tf, HLness_att_mask_tf, lstmRNN_variables_tf, lstm3_variables_tf = model.build_generator()
    sess = tf.InteractiveSession()

    saver = tf.train.Saver()
    saver.restore(sess, model_path)
    for ind, row in enumerate(lstmRNN_variables_tf):
	if ind % 4 == 0:
		assign_op = row.assign(tf.mul(row,1-0.5))
		sess.run(assign_op)
    for ind, row in enumerate(lstm3_variables_tf):
	if ind % 4 == 0:
		assign_op = row.assign(tf.mul(row,1-0.5))
		sess.run(assign_op)

    [mp, pred_sent, gt_sent, HLness] = testing_all(sess, test_data, ixtoword,video_tf, video_mask_tf, video_len_tf, HLness_tf, caption_tf, HLness_att_mask_tf)
    np.savez('HS_result/'+model_path.split('/')[1],gt = gt_sent,pred=pred_sent,mp=mp,HLness=HLness)
    total_score = np.mean(mp)
    print model_path.split('/')[1]+' mAP: ' + str(total_score)
    scorer = COCOScorer()
    total_score = scorer.score(gt_sent, pred_sent, range(len(pred_sent)))
    return total_score
开发者ID:KuoHaoZeng,项目名称:VH,代码行数:37,代码来源:HS.py

示例2: test

# 需要导入模块: from cocoeval import COCOScorer [as 别名]
# 或者: from cocoeval.COCOScorer import score [as 别名]
def test(model_path='models/model-900', video_feat_path=video_feat_path):
    meta_data, train_data, val_data, test_data = get_video_data_jukin(video_data_path_train, video_data_path_val, video_data_path_test)
    test_data = val_data
    ixtoword = pd.Series(np.load('./data'+str(gpu_id)+'/ixtoword.npy').tolist())

    model = Video_Caption_Generator(
            dim_image=dim_image,
            n_words=len(ixtoword),
            dim_hidden=dim_hidden,
            batch_size=batch_size,
            n_lstm_steps=n_frame_step,
	    drop_out_rate = 0,
            bias_init_vector=None)

    video_tf, video_mask_tf, caption_tf, lstm3_variables_tf = model.build_generator()
    sess = tf.InteractiveSession(config=tf.ConfigProto(allow_soft_placement=True))

    with tf.device("/cpu:0"):
	    saver = tf.train.Saver()
	    saver.restore(sess, model_path)
    
    for ind, row in enumerate(lstm3_variables_tf):
        if ind % 4 == 0:
                assign_op = row.assign(tf.mul(row,1-0.5))
                sess.run(assign_op)
    
    [pred_sent, gt_sent] = testing_all(sess, test_data, ixtoword,video_tf, video_mask_tf, caption_tf)
    #np.savez('Att_result/'+model_path.split('/')[1],gt = gt_sent,pred=pred_sent)
    scorer = COCOScorer()
    total_score = scorer.score(gt_sent, pred_sent, range(len(pred_sent)))
    return total_score
开发者ID:KuoHaoZeng,项目名称:VH,代码行数:33,代码来源:Att.py

示例3: score_with_cocoeval

# 需要导入模块: from cocoeval import COCOScorer [as 别名]
# 或者: from cocoeval.COCOScorer import score [as 别名]
def score_with_cocoeval(samples_valid, samples_test, engine):
    scorer = COCOScorer()
    if samples_valid:
        gts_valid = OrderedDict()
        for vidID in engine.valid_ids:
            gts_valid[vidID] = engine.CAP[vidID]
        valid_score = scorer.score(gts_valid, samples_valid, engine.valid_ids)
    else:
        valid_score = None
    if samples_test:
        gts_test = OrderedDict()
        for vidID in engine.test_ids:
            gts_test[vidID] = engine.CAP[vidID]
        test_score = scorer.score(gts_test, samples_test, engine.test_ids)
    else:
        test_score = None
    return valid_score, test_score
开发者ID:MichaelXin,项目名称:arctic-capgen-vid,代码行数:19,代码来源:metrics.py

示例4: train

# 需要导入模块: from cocoeval import COCOScorer [as 别名]
# 或者: from cocoeval.COCOScorer import score [as 别名]
def train():
    meta_data, train_data, val_data, test_data = get_video_data_jukin(video_data_path_train, video_data_path_val, video_data_path_test)
    captions = meta_data['Description'].values
    captions = map(lambda x: x.replace('.', ''), captions)
    captions = map(lambda x: x.replace(',', ''), captions)
    wordtoix, ixtoword, bias_init_vector = preProBuildWordVocab(captions, word_count_threshold=1)

    np.save('./data'+str(gpu_id)+'/ixtoword', ixtoword)

    model = Video_Caption_Generator(
            dim_image=dim_image,
            n_words=len(wordtoix),
            dim_hidden=dim_hidden,
            batch_size=batch_size,
            n_lstm_steps=n_frame_step,
	    drop_out_rate = 0.5,
            bias_init_vector=None)

    tf_loss, tf_video, tf_video_mask, tf_caption, tf_caption_mask= model.build_model()
    sess = tf.InteractiveSession(config=tf.ConfigProto(allow_soft_placement=True))

    with tf.device("/cpu:0"):
    	saver = tf.train.Saver(max_to_keep=100)
    train_op = tf.train.AdamOptimizer(learning_rate).minimize(tf_loss)
    tf.initialize_all_variables().run()
    saver.restore(sess, 'models_Att_update_new/model-30')

    tStart_total = time.time()
    for epoch in range(n_epochs):
        index = np.arange(len(train_data))
        np.random.shuffle(index)
        train_data = train_data[index]

	tStart_epoch = time.time()
	loss_epoch = np.zeros(len(train_data))
        for current_batch_file_idx in xrange(len(train_data)):

	    tStart = time.time()
	    current_batch = h5py.File(train_data[current_batch_file_idx])
            current_feats = np.zeros((batch_size, n_frame_step, dim_image))
            current_video_masks = np.zeros((batch_size, n_frame_step))
	    current_video_len = np.zeros(batch_size)
	    for ind in xrange(batch_size):
		current_feats[ind,:,:] = current_batch['data'][:,ind,:]
		idx = np.where(current_batch['label'][:,ind] != -1)[0]
		if len(idx) == 0:
			continue
		current_video_masks[ind,:idx[-1]+1] = 1

            current_captions = current_batch['title']
            current_caption_ind = map(lambda cap: [wordtoix[word] for word in cap.lower().split(' ') if word in wordtoix], current_captions)

            current_caption_matrix = sequence.pad_sequences(current_caption_ind, padding='post', maxlen=16-1)
            current_caption_matrix = np.hstack( [current_caption_matrix, np.zeros( [len(current_caption_matrix),1]) ] ).astype(int)
            current_caption_masks = np.zeros((current_caption_matrix.shape[0], current_caption_matrix.shape[1]))
            nonzeros = np.array( map(lambda x: (x != 0).sum()+1, current_caption_matrix ))

            for ind, row in enumerate(current_caption_masks):
                row[:nonzeros[ind]] = 1

            _, loss_val = sess.run(
                    [train_op, tf_loss],
                    feed_dict={
                        tf_video: current_feats,
                        tf_video_mask : current_video_masks,
                        tf_caption: current_caption_matrix,
                        tf_caption_mask: current_caption_masks
                        })
	    loss_epoch[current_batch_file_idx] = loss_val
	    tStop = time.time()
            #print "Epoch:", epoch, " Batch:", current_batch_file_idx, " Loss:", loss_val
	    #print "Time Cost:", round(tStop - tStart,2), "s"

	print "Epoch:", epoch, " done. Loss:", np.mean(loss_epoch)
	tStop_epoch = time.time()
	print "Epoch Time Cost:", round(tStop_epoch - tStart_epoch,2), "s"

        if np.mod(epoch, 10) == 0 or epoch == n_epochs - 1:
            print "Epoch ", epoch, " is done. Saving the model ..."
    	    with tf.device("/cpu:0"):
            	saver.save(sess, os.path.join(model_path, 'model'), global_step=epoch)

	    current_batch = h5py.File(val_data[np.random.randint(0,len(val_data))])
    	    video_tf, video_mask_tf, caption_tf, lstm3_variables_tf = model.build_generator()
    	    ixtoword = pd.Series(np.load('./data'+str(gpu_id)+'/ixtoword.npy').tolist())
	    [pred_sent, gt_sent] = testing_all(sess, train_data[-2:], ixtoword, video_tf, video_mask_tf, caption_tf)
	    for idx in range(len(pred_sent)):
		print "GT:  " + gt_sent[idx][0]['caption']
		print "PD:  " + pred_sent[idx][0]['caption']
		print '-------'
    	    [pred_sent, gt_sent] = testing_all(sess, val_data, ixtoword,video_tf, video_mask_tf, caption_tf)
	    scorer = COCOScorer()
	    total_score = scorer.score(gt_sent, pred_sent, range(len(pred_sent)))
	sys.stdout.flush()

    print "Finally, saving the model ..."
    with tf.device("/cpu:0"):
    	saver.save(sess, os.path.join(model_path, 'model'), global_step=n_epochs)
    tStop_total = time.time()
    print "Total Time Cost:", round(tStop_total - tStart_total,2), "s"
开发者ID:KuoHaoZeng,项目名称:VH,代码行数:102,代码来源:Att.py

示例5: train

# 需要导入模块: from cocoeval import COCOScorer [as 别名]
# 或者: from cocoeval.COCOScorer import score [as 别名]

#.........这里部分代码省略.........
        ## init queue
        data_queue = mp.Queue(nr_prefetch)
#        tracker_queue = mp.Queue(nr_prefetch)
        title_queue = mp.Queue(nr_prefetch)
        t1 = Thread(target=load_data_into_queue, args=(train_data, data_queue, 'data'))
#        t2 = Thread(target=load_data_into_queue, args=(train_data, tracker_queue, 'tracker'))
        t3 = Thread(target=load_data_into_queue, args=(train_data, title_queue, 'title'))
        t1.start()
#        t2.start()
        t3.start()
        for current_batch_file_idx in range(len(train_data)):
            tStart = time.time()
            current_batch = h5py.File(train_data[current_batch_file_idx])
            current_feats = np.zeros((batch_size, n_frame_step, dim_image))
            current_video_masks = np.zeros((batch_size, n_frame_step))
            current_video_len = np.zeros(batch_size)
            
            if 'tracker' in current_batch.keys():
                current_tracker = np.array(current_batch['tracker'])
            else:
                current_tracker = np.zeros((batch_size, tracker_cnt, dim_tracker))
            
            if 'tracker_mask' in current_batch.keys():
                current_tracker_mask = np.array(current_batch['tracker_mask'])
            else:
                current_tracker_mask = np.zeros((batch_size, tracker_cnt))

#            current_tracker = tracker_queue.get()
            current_batch_data = data_queue.get()
            current_batch_title = title_queue.get()
            for ind in xrange(batch_size):
                current_feats[ind,:,:] = current_batch_data[:,ind,:]
                idx = np.where(current_batch['label'][:,ind] != -1)[0]
                if len(idx) == 0:
                        continue
                current_video_masks[ind,idx[-1]] = 1

            current_captions = current_batch_title
            current_caption_ind = map(lambda cap: [wordtoix[word] for word in cap.lower().split(' ') if word in wordtoix], current_captions)

            current_caption_matrix = sequence.pad_sequences(current_caption_ind, padding='post', maxlen=35-1)
            current_caption_matrix = np.hstack( [current_caption_matrix, np.zeros( [len(current_caption_matrix),1]) ] ).astype(int)
            current_caption_masks = np.zeros((current_caption_matrix.shape[0], current_caption_matrix.shape[1]))
            nonzeros = np.array( map(lambda x: (x != 0).sum()+1, current_caption_matrix ))

            for ind, row in enumerate(current_caption_masks):
                row[:nonzeros[ind]] = 1

            current_batch.close()


            _, loss_val= sess.run(
                [train_op, tf_loss],
                feed_dict={
                tf_video: current_feats,
                tf_video_mask : current_video_masks,
                tf_tracker : current_tracker,
                tf_tracker_mask : current_tracker_mask,
                tf_caption: current_caption_matrix,
                tf_caption_mask: current_caption_masks
                })
            #writer.add_summary(summary_str, epoch)
            loss_epoch[current_batch_file_idx] = loss_val
            tStop = time.time()
            #print "Epoch:", epoch, " Batch:", current_batch_file_idx, " Loss:", loss_val
            #print "Time Cost:", round(tStop - tStart,2), "s"

        t1.join()
#       t2.join()
        t3.join()
        print "Epoch:", epoch, " done. Loss:", np.mean(loss_epoch)
        tStop_epoch = time.time()
        print "Epoch Time Cost:", round(tStop_epoch - tStart_epoch,2), "s"
	sys.stdout.flush()

        if np.mod(epoch, 2) == 0:
            print "Epoch ", epoch, " is done. Saving the model ..."
    	    with tf.device('/cpu:0'):
            	saver.save(sess, os.path.join(model_path, 'model'), global_step=epoch)
        if np.mod(epoch, 10) == 0:
            current_batch = h5py.File(val_data[np.random.randint(0,len(val_data))])
            video_tf, video_mask_tf, tracker_tf, tracker_mask_tf, caption_tf, lstm1_variables_tf, lstm2_variables_tf = model.build_generator()
            ixtoword = pd.Series(np.load('./data_all/ixtoword.npy').tolist())
#            [pred_sent, gt_sent, id_list, gt_dict, pred_dict, fnamelist] = testing_all_multi_gt(sess, train_data[-2:], ixtoword,video_tf, video_mask_tf, tracker_tf, tracker_mask_tf, caption_tf)
#            for key in pred_dict.keys():
#                for ele in gt_dict[key]:
#                    print "GT:  " + ele['caption']
#                print "PD:  " + pred_dict[key][0]['caption']
#                print '-------'

            [pred_sent, gt_sent, id_list, gt_dict, pred_dict, fnamelist] = testing_all_multi_gt(sess, val_data, ixtoword,video_tf, video_mask_tf, tracker_tf, tracker_mask_tf, caption_tf)

            scorer = COCOScorer()
            total_score = scorer.score(gt_dict, pred_dict, id_list)

    print "Finally, saving the model ..."
    with tf.device('/cpu:0'):
	    saver.save(sess, os.path.join(model_path, 'model'), global_step=n_epochs)
    tStop_total = time.time()
    print "Total Time Cost:", round(tStop_total - tStart_total,2), "s"
开发者ID:tsenghungchen,项目名称:SA-tensorflow,代码行数:104,代码来源:SS_queue.py

示例6: train

# 需要导入模块: from cocoeval import COCOScorer [as 别名]
# 或者: from cocoeval.COCOScorer import score [as 别名]

#.........这里部分代码省略.........

    tf_loss, tf_video, tf_video_mask, tf_video_len, tf_caption, tf_caption_mask, tf_HLness, tf_HLness_mask, tf_HLness_att_mask= model.build_model()
    loss_summary = tf.scalar_summary("Loss",tf_loss)
    sess = tf.InteractiveSession()
    merged = tf.merge_all_summaries()
    writer = tf.train.SummaryWriter('/tmp/tf_log', sess.graph_def)

    saver = tf.train.Saver(max_to_keep=100)
    train_op = tf.train.AdamOptimizer(learning_rate).minimize(tf_loss)
    tf.initialize_all_variables().run()

    tStart_total = time.time()
    for epoch in range(n_epochs):
        index = np.arange(len(train_data))
        np.random.shuffle(index)
        train_data = train_data[index]

	tStart_epoch = time.time()
	loss_epoch = np.zeros(len(train_data))
        for current_batch_file_idx in xrange(len(train_data)):

	    tStart = time.time()
	    current_batch = h5py.File(train_data[current_batch_file_idx])
            current_feats = np.zeros((batch_size, n_frame_step, dim_image))
	    current_HLness = np.zeros((batch_size, n_frame_step))
	    current_HLness_masks = np.zeros((batch_size, n_frame_step))
	    current_HLness_att_masks = np.zeros((batch_size, n_frame_step))
            current_video_masks = np.zeros((batch_size, n_frame_step))
	    current_video_len = np.zeros(batch_size)
	    for ind in xrange(batch_size):
		current_feats[ind,:,:] = current_batch['data'][:,ind,:]
		idx = np.where(current_batch['label'][:,ind] != -1)[0]
		if len(idx) == 0:
			continue
		idy = np.where(current_batch['label'][:,ind] == 1)[0]
		if len(idy) == 0:
			continue
		current_HLness[ind,idx] = current_batch['label'][idx,ind]
		current_HLness_masks[ind,idx] = 1
		current_video_masks[ind,idy[-1]] = 1
		current_video_len[ind] = idx[-1] + 1
		current_HLness_att_masks[ind,idy] = 1
		if(idy[0] > 4):
			current_HLness_att_masks[ind,idy[0]-5:idy[0]] = 1
		else:
			current_HLness_att_masks[ind,0:idy[0]] = 1

            current_captions = current_batch['title']
            current_caption_ind = map(lambda cap: [wordtoix[word] for word in cap.lower().split(' ') if word in wordtoix], current_captions)

            current_caption_matrix = sequence.pad_sequences(current_caption_ind, padding='post', maxlen=15-1)
            current_caption_matrix = np.hstack( [current_caption_matrix, np.zeros( [len(current_caption_matrix),1]) ] ).astype(int)
            current_caption_masks = np.zeros((current_caption_matrix.shape[0], current_caption_matrix.shape[1]))
            nonzeros = np.array( map(lambda x: (x != 0).sum()+1, current_caption_matrix ))

            for ind, row in enumerate(current_caption_masks):
                row[:nonzeros[ind]] = 1

            _, loss_val, summary_str= sess.run(
                    [train_op, tf_loss, merged],
                    feed_dict={
                        tf_video: current_feats,
                        tf_video_mask : current_video_masks,
                        tf_caption: current_caption_matrix,
                        tf_caption_mask: current_caption_masks,
			tf_HLness: current_HLness,
			tf_HLness_mask: current_HLness_masks,
			tf_HLness_att_mask: current_HLness_att_masks
                        })
	    writer.add_summary(summary_str, epoch)
	    loss_epoch[current_batch_file_idx] = loss_val
	    tStop = time.time()
            #print "Epoch:", epoch, " Batch:", current_batch_file_idx, " Loss:", loss_val
	    #print "Time Cost:", round(tStop - tStart,2), "s"

	print "Epoch:", epoch, " done. Loss:", np.mean(loss_epoch)
	tStop_epoch = time.time()
	print "Epoch Time Cost:", round(tStop_epoch - tStart_epoch,2), "s"

        if np.mod(epoch, 20) == 0:
            print "Epoch ", epoch, " is done. Saving the model ..."
            saver.save(sess, os.path.join(model_path, 'model'), global_step=epoch)

	    current_batch = h5py.File(test_data[np.random.randint(0,len(test_data))])
    	    video_tf, video_mask_tf, video_len_tf, HLness_tf, caption_tf, HLness_att_mask_tf, lstmRNN_variables_tf, lstm3_variables_tf = model.build_generator()
    	    ixtoword = pd.Series(np.load('./data/ixtoword.npy').tolist())
	    #[mp, pred_sent, gt_sent, HLness] = testing_one(sess, current_batch, ixtoword,video_tf, video_len_tf, HLness_tf, caption_tf, HLness_att_mask_tf)
    	    [mp, pred_sent, gt_sent, HLness] = testing_all(sess, test_data, ixtoword,video_tf, video_mask_tf, video_len_tf, HLness_tf, caption_tf, HLness_att_mask_tf)
	    #for xxx in xrange(current_batch['label'].shape[1]):
	    #	print gt_sent[xxx]
	    #	print pred_sent[xxx]
	    total_score = np.mean(mp)
	    print total_score
	    scorer = COCOScorer()
	    total_score = scorer.score(gt_sent, pred_sent, range(len(pred_sent)))

    print "Finally, saving the model ..."
    saver.save(sess, os.path.join(model_path, 'model'), global_step=n_epochs)
    tStop_total = time.time()
    print "Total Time Cost:", round(tStop_total - tStart_total,2), "s"
开发者ID:KuoHaoZeng,项目名称:VH,代码行数:104,代码来源:HS.py

示例7: train

# 需要导入模块: from cocoeval import COCOScorer [as 别名]
# 或者: from cocoeval.COCOScorer import score [as 别名]

#.........这里部分代码省略.........
    np.save("./data" + str(gpu_id) + "/ixtoword", ixtoword)

    model = Video_Caption_Generator(
        dim_image=dim_image,
        n_words=len(wordtoix),
        dim_hidden=dim_hidden,
        batch_size=batch_size,
        n_lstm_steps=n_frame_step,
        drop_out_rate=0.5,
        bias_init_vector=None,
    )

    tf_loss, tf_video, tf_video_mask, tf_caption, tf_caption_mask = model.build_model()
    loss_summary = tf.scalar_summary("Loss", tf_loss)
    sess = tf.InteractiveSession(config=tf.ConfigProto(allow_soft_placement=True))
    merged = tf.merge_all_summaries()
    writer = tf.train.SummaryWriter("/tmp/tf_log", sess.graph_def)

    saver = tf.train.Saver(max_to_keep=100)
    train_op = tf.train.AdamOptimizer(learning_rate).minimize(tf_loss)
    tf.initialize_all_variables().run()
    saver.restore(sess, "models_SS_youtube_notest_dummy/model-20")

    tStart_total = time.time()
    for epoch in range(n_epochs):
        index = np.arange(len(train_data))
        np.random.shuffle(index)
        train_data = train_data[index]

        tStart_epoch = time.time()
        loss_epoch = np.zeros(len(train_data))
        for current_batch_file_idx in xrange(len(train_data)):

            tStart = time.time()
            current_batch = h5py.File(train_data[current_batch_file_idx])
            current_feats = np.zeros((batch_size, n_frame_step, dim_image))
            current_video_masks = np.zeros((batch_size, n_frame_step))
            current_video_len = np.zeros(batch_size)
            for ind in xrange(batch_size):
                current_feats[ind, :, :] = current_batch["data"][:, ind, :]
                idx = np.where(current_batch["label"][:, ind] != -1)[0]
                if len(idx) == 0:
                    continue
                current_video_masks[ind, idx[-1]] = 1

            current_captions = current_batch["title"]
            current_caption_ind = map(
                lambda cap: [wordtoix[word] for word in cap.lower().split(" ") if word in wordtoix], current_captions
            )

            current_caption_matrix = sequence.pad_sequences(current_caption_ind, padding="post", maxlen=16 - 1)
            current_caption_matrix = np.hstack(
                [current_caption_matrix, np.zeros([len(current_caption_matrix), 1])]
            ).astype(int)
            current_caption_masks = np.zeros((current_caption_matrix.shape[0], current_caption_matrix.shape[1]))
            nonzeros = np.array(map(lambda x: (x != 0).sum() + 1, current_caption_matrix))

            for ind, row in enumerate(current_caption_masks):
                row[: nonzeros[ind]] = 1

            _, loss_val, summary_str = sess.run(
                [train_op, tf_loss, merged],
                feed_dict={
                    tf_video: current_feats,
                    tf_video_mask: current_video_masks,
                    tf_caption: current_caption_matrix,
                    tf_caption_mask: current_caption_masks,
                },
            )
            writer.add_summary(summary_str, epoch)
            loss_epoch[current_batch_file_idx] = loss_val
            tStop = time.time()
            # print "Epoch:", epoch, " Batch:", current_batch_file_idx, " Loss:", loss_val
            # print "Time Cost:", round(tStop - tStart,2), "s"

        print "Epoch:", epoch, " done. Loss:", np.mean(loss_epoch)
        tStop_epoch = time.time()
        print "Epoch Time Cost:", round(tStop_epoch - tStart_epoch, 2), "s"
        sys.stdout.flush()

        if np.mod(epoch, 10) == 0:
            print "Epoch ", epoch, " is done. Saving the model ..."
            saver.save(sess, os.path.join(model_path, "model"), global_step=epoch)

            current_batch = h5py.File(val_data[np.random.randint(0, len(val_data))])
            video_tf, video_mask_tf, caption_tf, lstm1_variables_tf, lstm2_variables_tf = model.build_generator()
            ixtoword = pd.Series(np.load("./data" + str(gpu_id) + "/ixtoword.npy").tolist())
            [pred_sent, gt_sent] = testing_all(sess, train_data[-2:], ixtoword, video_tf, video_mask_tf, caption_tf)
            for idx in range(len(pred_sent)):
                print "GT:  " + gt_sent[idx][0]["caption"]
                print "PD:  " + pred_sent[idx][0]["caption"]
                print "-------"
            [pred_sent, gt_sent] = testing_all(sess, val_data, ixtoword, video_tf, video_mask_tf, caption_tf)
            scorer = COCOScorer()
            total_score = scorer.score(gt_sent, pred_sent, range(len(pred_sent)))

    print "Finally, saving the model ..."
    saver.save(sess, os.path.join(model_path, "model"), global_step=n_epochs)
    tStop_total = time.time()
    print "Total Time Cost:", round(tStop_total - tStart_total, 2), "s"
开发者ID:KuoHaoZeng,项目名称:VH,代码行数:104,代码来源:SS_youtube_notest_dummy.py


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