python - 使用 `tf.image.resize_image_with_crop_or_pad` 来调整 numpy 数组的大小
问题描述
我想tf.image.resize_image_with_crop_or_pad
在一个 Numpy 形状数组上使用(100,100,2)
它来裁剪或填充到目标形状(h,w,2)
。
但是,当我这样做时:
img = resize_image_with_crop_or_pad(img, target_height, target_width)
img = np.array(img)
img.shape
评估为()
,这不是我所期望的。如何将此函数的输出转换为形状正确的 numpy 数组?
解决方案
img = resize_image_with_crop_or_pad(img_tensor, target_height, target_width)
with tf.Session as sess:
img_output = sess.run(img)
Nowimg_output
是一个 numpy 数组,但请注意 img 必须是一个tf.Tensor
形状[1, height, width, channels]
,因此您可以事先执行此操作,这表明您的输入图像已经是一个 numpy 数组:
img_input = np.expand_dims(img_input, 0)
img_tensor = tf.convert_to_tensor(img_input)
推荐阅读
- html - 一个项目不想留在原地
- sql-server - SQL Server FOR XML 查询未在预期层次结构中返回结果
- python - 用于更新 JSON 文件的 python 脚本
- php - PHP登录脚本运行时提示失败
- asp.net - dotnet 核心中可能需要 ViewModel 的枚举?
- android - kotlin 和 android:是否有必要取消以前设置的回调?
- javascript - 如何从 npm 模块导入 css 文件 - webcomponent
- yocto - 如何让spi连接mcp251x和yocto?
- java - 如何使edittext适合两个按钮?
- python-sphinx - 在主文档中包含指令