如何为我的模型实现f1分数计算器?

问题描述

我想在我的模型中使用它来计算f分数:

Y_pred = sess.run([nn_output],Feed_dict={input_images: input_data[0],input_seg_maps: input_data[2],input_training_masks: input_data[3]})

ClassificationReport = sklearn.metrics.classification_report(Y_pred,Y_true,output_dict=True)

但是我很困惑Y_true是什么?我认为这应该是我的数据集的基本事实,但我不知道如何实现它。

这是我计算模型损失和总损失但无法在其中实现f分数计算代码代码

with tf.Session(config=tf.ConfigProto(gpu_options=gpu_options,allow_soft_placement=True)) as sess:
        if FLAGS.restore:
            logger.info('continue training from prevIoUs checkpoint')
            ckpt = tf.train.latest_checkpoint(FLAGS.checkpoint_path)
            logger.debug(ckpt)
            saver.restore(sess,ckpt)
        else:
            sess.run(init)
            if FLAGS.pretrained_model_path is not None:
                variable_restore_op(sess)

        data_generator = data_provider.get_batch(num_workers=FLAGS.num_readers,input_size=FLAGS.input_size,batch_size=FLAGS.batch_size_per_gpu * len(gpus))

        start = time.time()
        for step in range(FLAGS.max_steps):
            data = next(data_generator)
            ml,tl,_ = sess.run([model_loss,total_loss,train_op],Feed_dict={input_images: data[0],input_seg_maps: data[2],input_training_masks: data[3]})
            
            Y_pred = sess.run([nn_output],input_training_masks: input_data[3]}) # Feed according to your model

            ClassificationReport = sklearn.metrics.classification_report(Y_pred,output_dict=True)

            if np.isnan(tl):
                logger.error('Loss diverged,stop training')
                break

            if step % 10 == 0:
                avg_time_per_step = (time.time() - start)/10
                avg_examples_per_second = (10 * FLAGS.batch_size_per_gpu * len(gpus))/(time.time() - start)
                start = time.time()
                logger.info('Step {:06d},model loss {:.4f},total loss {:.4f},{:.2f} seconds/step,{:.2f} examples/second'.format(
                    step,ml,avg_time_per_step,avg_examples_per_second))

            if step % FLAGS.save_checkpoint_steps == 0:
                saver.save(sess,os.path.join(FLAGS.checkpoint_path,'model.ckpt'),global_step=global_step)

            if step % FLAGS.save_summary_steps == 0:
                _,summary_str = sess.run([train_op,summary_op],input_training_masks: data[3]})
                summary_writer.add_summary(summary_str,global_step=step)

我仍然不确定在哪里计算我的f分数。我认为应该在计算模型损失的地方,但是我不确定给出Y_true值所需的函数。我可以发送指向Im试图实现的模型和数据集的链接

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)