XiaoMi / mace-models

Mobile AI Compute Engine Model Zoo
Apache License 2.0
368 stars 72 forks source link

.yml中只有input和output的placeholder? #24

Closed Ijustakid closed 4 years ago

Ijustakid commented 4 years ago

自训练模型过程中添加了keep_prob的placeholder,生成.pb也没问题,但是: python tools/python/convert.py --config ../mace-models/mobilenet-v1/mobilenet-v1.yml 时出现: InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'is_training' with dtype bool [[Node: is_training = Placeholder[dtype=DT_BOOL, shape=<unknown>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]

请问如何解决?

Ijustakid commented 4 years ago

mobilenet-v1.yml

lee-bin commented 4 years ago

@Ijustakid 在导出TensorFlow模型的时候需要设置is_training为false

Ijustakid commented 4 years ago

@Ijustakid 在导出TensorFlow模型的时候需要设置is_training为false convert_pb.py中:

out=sess.run(output_tensor_name, feed_dict={input_image_tensor: im,
input_keep_prob_tensor:1.0,
input_is_training_tensor:False})

已把is_training_tensor设为False 另:keep_prob的placeholder如何处理?

十分感谢!

br

Ijustakid commented 4 years ago

@Ijustakid 在导出TensorFlow模型的时候需要设置is_training为false

convert_pb.py

`input_image_tensor = sess.graph.get_tensor_by_name("input:0") input_keep_prob_tensor = sess.graph.get_tensor_by_name("keep_prob:0") input_is_training_tensor = sess.graph.get_tensor_by_name("is_training:0")

        # 定义输出的张量名称
        output_tensor_name = sess.graph.get_tensor_by_name("MobilenetV1/Logits/SpatialSqueeze:0")

        # 读取测试图片
        im=read_image(image_path,resize_height,resize_width,normalization=True)
        im=im[np.newaxis,:]
        # 测试读出来的模型是否正确,注意这里传入的是输出和输入节点的tensor的名字,不是操作节点的名字
        # out=sess.run("InceptionV3/Logits/SpatialSqueeze:0", feed_dict={'input:0': im,'keep_prob:0':1.0,'is_training:0':False})
        out=sess.run(output_tensor_name, feed_dict={input_image_tensor: im,
                                                    input_keep_prob_tensor:1.0,
                                                    input_is_training_tensor:False})`
lee-bin commented 4 years ago

没看到模型构建和导出的代码,只看到了session.run运行的代码,需要在模型构建时设置is_training和keep_prob

Ijustakid commented 4 years ago

没看到模型构建和导出的代码,只看到了session.run运行的代码,需要在模型构建时设置is_training和keep_prob

i will try it, thanks!