Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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 如何在Tensorflow Slim中加载NasNet_Python_Tensorflow - Fatal编程技术网

Python 如何在Tensorflow Slim中加载NasNet

Python 如何在Tensorflow Slim中加载NasNet,python,tensorflow,Python,Tensorflow,从列表中下载适当的模型数据后,我可以加载,例如,ResNet-50,如下所示: graph = tf.Graph() with graph.as_default(): img_p = tf.placeholder(tf.uint8, (None, *img_shape)) processed_img = tf.cast(img_p, tf.float32) - rgb_means with slim.arg_scope(resnet_v2.resnet_arg_scop

从列表中下载适当的模型数据后,我可以加载,例如,ResNet-50,如下所示:

graph = tf.Graph()
with graph.as_default():
    img_p = tf.placeholder(tf.uint8, (None, *img_shape))
    processed_img = tf.cast(img_p, tf.float32) - rgb_means

    with slim.arg_scope(resnet_v2.resnet_arg_scope()):
        logits, endpoints = resnet_v2.resnet_v2_50(processed_img, num_classes=1001, is_training=False)

    init_fn = slim.assign_from_checkpoint_fn('pretrained/resnet_v2_50.ckpt',
                                             slim.get_model_variables('resnet_v2_50'))

sess = tf.Session(config=config, graph=graph)
init_fn(sess)
NasNet的类似物是什么?实际上没有
.ckpt
文件,我也不确定要加载哪些变量。我可以成功创建模型,但无法恢复预训练的权重。我已尝试传入
.cpkt.index
文件,但未指定
slim.get\u model\u变量的范围

graph = tf.Graph()
with graph.as_default():
    img_p = tf.placeholder(tf.uint8, (None, *img_shape))

    processed_img = tf.image.convert_image_dtype(img_p, tf.float32)
    processed_img = 2 * (processed_img - 0.5)

    with slim.arg_scope(nasnet.nasnet_mobile_arg_scope()):
        logits, endpoints = nasnet.build_nasnet_mobile(processed_img, num_classes=1, is_training=False)

    init_fn = slim.assign_from_checkpoint_fn('pretrained/nasnet_small/model.ckpt.index',
                                            slim.get_model_variables())

sess = tf.Session(config=config, graph=graph)
init_fn(sess)
但这会产生以下错误:

NotFoundError: Tensor name "cell_4/comb_iter_0/right/bn_sep_3x3_1/gamma" not found in checkpoint files pretrained/nasnet_small/model.ckpt.index
[[Node: save/RestoreV2_439 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2_439/tensor_names, save/RestoreV2_439/shape_and_slices)]]
[[Node: save/RestoreV2_317/_1597 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/device:GPU:0", send_device="/job:localhost/replica:0/task:0/device:CPU:0", send_device_incarnation=1, tensor_name="edge_3852_save/RestoreV2_317", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:GPU:0"]()]]

有人知道如何加载NasNet模型吗?(我不想从命令行界面使用它们)

您可以使用以下实现: