2 回答

TA贡献1862条经验 获得超7个赞
我正在处理的图像被标准化为 [0,1]。当转换为列表时,图像的每个像素都具有不必要的大量精度:
[[[0.4, 0.41568627450980394, 0.4117647058823529],
[0.39215686274509803, 0.403921568627451, 0.403921568627451],
[0.38823529411764707, 0.4, 0.4],
[0.3803921568627451, 0.39215686274509803, 0.3843137254901961],
[0.3803921568627451, 0.38823529411764707, 0.38823529411764707],
...
[0.11764705882352941, 0.12941176470588237, 0.12549019607843137],
[0.11764705882352941, 0.12941176470588237, 0.12549019607843137],
[0.11764705882352941, 0.12941176470588237, 0.12549019607843137]]]
一个快速而肮脏的解决方法是使用 np.around():
img_list = np.around(img_np, 4).tolist()
结果低于有效载荷大小限制。

TA贡献1816条经验 获得超4个赞
发送如此大的整数数组通常效率不高(您将花费大量时间编码和解码这些数组、网络延迟等)。这篇文章提供了一些选项(包括tolist您尝试过的)。
我会推荐“打包为字节字符串的张量”或“压缩图像数据”。
更新 10/19/2018
为了使用这些方法,您需要修改您的图表。如果您能够重新导出模型,那是最简单的。代替:
images = tf.placeholder(dtype=tf.uint8, shape=[None, None, None, 3])
你会使用:
raw_byte_strings = tf.placeholder(dtype=tf.string, shape=[None])
decode = lambda raw_byte_str: tf.decode_raw(raw_byte_str, tf.uint8)
images = tf.map_fn(decode, raw_byte_strings, dtype=tf.uint8)
添加回答
举报