Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TF-Slim与初始预测概率_Python_Tensorflow_Tf Slim - Fatal编程技术网

Python TF-Slim与初始预测概率

Python TF-Slim与初始预测概率,python,tensorflow,tf-slim,Python,Tensorflow,Tf Slim,我已经使用tfslim(v1.3)培训了《盗梦空间》v4的最后几层,我正试图将处理集成到现有的工具中,但我在弄清楚如何生成预测方面遇到了困难。我想要所有的预测值,而不仅仅是argmax。我有一个检查点路径和一些带有图像的numpy数组(100x100x3,这是我训练的内容…但扩展到299x299x3)。有人能给我指出正确的方向吗?我将提供多个图像以供评估,但不一定是成批提供(我可能会运行一个微服务,获取一个或多个图像并返回结果,但只加载一次检查点以缩短初始化时间)。下面是一个如何执行此操作的示例

我已经使用tfslim(v1.3)培训了《盗梦空间》v4的最后几层,我正试图将处理集成到现有的工具中,但我在弄清楚如何生成预测方面遇到了困难。我想要所有的预测值,而不仅仅是argmax。我有一个检查点路径和一些带有图像的numpy数组(100x100x3,这是我训练的内容…但扩展到299x299x3)。有人能给我指出正确的方向吗?我将提供多个图像以供评估,但不一定是成批提供(我可能会运行一个微服务,获取一个或多个图像并返回结果,但只加载一次检查点以缩短初始化时间)。

下面是一个如何执行此操作的示例:

   with tf.Graph().as_default():
        tf_global_step = slim.get_or_create_global_step()
        network_fn = nets_factory.get_network_fn("inception_v4",
            num_classes=5,
            is_training=False)

        ##############################################################
        # Create a dataset provider that loads data from the dataset #
        ##############################################################
        provider = slim.dataset_data_provider.DatasetDataProvider(
            dataset,
            shuffle=False,
            common_queue_capacity=2,
            common_queue_min=1)
        [images] = provider.get(['image'])

        #####################################
        # Select the preprocessing function #
        #####################################
        image_preprocessing_fn = preprocessing_factory.get_preprocessing(
            "inception_v4",
            is_training=False)

        eval_image_size = network_fn.default_image_size
        images = image_preprocessing_fn(images, eval_image_size, eval_image_size)
        images = tf.reshape(images, [eval_image_size, eval_image_size, 3])
        images, _ = tf.train.batch(
                [images, 0],
                batch_size=len(dataset.data_sources),
                num_threads=1,
                capacity=len(dataset.data_sources))
        ####################
        # Define the model #
        ####################
        logits, _ = network_fn(images)
        variables_to_restore = slim.get_variables_to_restore()

        soft = tf.nn.softmax(logits, 1)
        predictions = tf.argmax(logits, 1)
        num_batches = 1

        if tf.gfile.IsDirectory(checkpoint_path):
            checkpoint_path = tf.train.latest_checkpoint(checkpoint_path)

        tf.logging.info('Evaluating %s' % checkpoint_path)
        r_logits, r_soft, r_prediction = slim.evaluation.evaluate_once(
            master='',
            checkpoint_path=checkpoint_path,
            logdir=eval_dir,
            num_evals=num_batches,
            eval_op=[],
            final_op=[logits, soft, predictions],
            variables_to_restore=variables_to_restore)