我是R用户,对Python和TensorFlow都是新手,并且一直在努力让我的再培训图像分类器在修改label_image.py以便与Mobilenets一起使用时实际做出预测。我发现了这个问题,并知道我需要实现从this tutorial的最后一行,但我无法弄清楚如何。如何在Python中为Tensorflow Mobilenet预测将字节图像从[0,255]转换为[-1,1]浮点范围?
If you're going to be using the Mobilenet models in label_image or your own programs, you'll need to feed in an image of the specified size converted to a float range into the 'input' tensor. Typically 24-bit images are in the range [0,255], and you must convert them to the [-1,1] float range expected by the model with the formula (image - 128.)/128..
在R我习惯于处理JPEG作为3维数组。如果是这种格式,我会知道该怎么做,但从tf.gfile.FastGFile("fileName.jpg", 'rb').read()
返回的图像类型是bytes
。我真的不明白这是什么。直接应用它们给图像对象的公式返回TypeError: unsupported operand type(s) for -: 'bytes' and 'float'
。我假设在改变范围之后,我仍然需要它以bytes
的格式将它馈送到网络中,但我还没有100%清楚。任何澄清这个对象类型是什么以及如何使用它将非常感激。
谢谢!我认为在第三行你的意思是要img_decoded的图像,对吗?这是我需要的一部分,但现在它是一个张量对象。我如何将它恢复到之前的同一种二进制字符串? –
是的,它返回解码后的jpeg图像,将解码的张量再次编码为二进制串,可以使用'tf.image.encode_jpeg(some_image)' –
这是我的怀疑,但它给了我一个“TypeError:Input”图像'的'EncodeJpeg'Op的类型为float32,与uint8的预期类型不匹配。“ API中列出的所有参数在我看来都没有明显的修正,所以我认为我在错误的轨道上。 –