小编Ant*_*nt1的帖子

如何检索 tf.image.decode_jpeg 返回的图像张量的高度和高度?

我尝试设置一个图像管道,为 Tensorflow 构建一个图像数据集来裁剪图像。我遵循了本教程,但我想将文件裁剪为正方形,而不是在不保留纵横比的情况下调整其大小。我无法弄清楚如何获得它们的尺寸。

#
from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
#

import glob


AUTOTUNE = tf.data.experimental.AUTOTUNE
IMAGE_SIZE = 192


def preprocess_image(path):
    img_raw = tf.io.read_file(path)
    img_tensor = tf.image.decode_jpeg(img_raw, channels=3)
    print("img_tensor")
    print(img_tensor)
    height = img_tensor.shape[0]
    print("height")
    print(height)
    return img_tensor


files_path = glob.glob('./images/*.jpeg')
image_count = len(files_path)
path_ds = tf.data.Dataset.from_tensor_slices(files_path)
path_ds.map(preprocess_image, num_parallel_calls=AUTOTUNE)

Run Code Online (Sandbox Code Playgroud)

返回的张量形状tf.image.decode_jpeg 是:

Tensor("DecodeJpeg:0", shape=(None, None, 3), dtype=uint8)
Run Code Online (Sandbox Code Playgroud)

如何访问 jpg 图像的大小?

当我以这种方式访问​​它时,它可以工作:

#
from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
# …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

5
推荐指数
1
解决办法
2345
查看次数

在 @formatjs/intl-relativetimeformat/dist/locale-data/ 中哪里可以找到美国的语言环境

我正在将react-intl迁移到3.0版本,并且需要为IE填充语言环境数据。具体来说,我想加载 en-US 的区域设置数据的填充。我只能找到@formatjs/intl-relativetimeformat/dist/locale-data/en语言环境文件。

if (!Intl.RelativeTimeFormat) {
  // eslint-disable-next-line global-require
  require('@formatjs/intl-relativetimeformat/polyfill');
  // eslint-disable-next-line global-require
  require('@formatjs/intl-relativetimeformat/dist/locale-data/en-US');
}
Run Code Online (Sandbox Code Playgroud)

它会导致此错误:

Module not found: Error: Can't resolve '@formatjs/intl-relativetimeformat/dist/locale-data/en-US' in '/xxx/xxx/xxx/xxx/app'

reactjs formatjs

5
推荐指数
1
解决办法
3128
查看次数

当我尝试在 Tensorflow 中调整图像大小时如何修复“TypeError: x 和 y must have the same dtype, got tf.uint8 != tf.float32”

我尝试设置一个图像管道,为 Tensorflow 构建一个图像数据集来裁剪图像,但我无法裁剪图片。我遵循了本教程,但我想将文件裁剪为正方形,而不是在不保留纵横比的情况下调整其大小。
这是我的代码:

#
import tensorflow as tf
#

img_raw = tf.io.read_file('./images/4c34476047bcbbfd10b1fd3342605659.jpeg/')

img_tensor = tf.image.decode_jpeg(img_raw, channels=3)

img_final = tf.image.crop_to_bounding_box(
    img_tensor,
    0,
    0,
    200,
    200
)

img_final /= 255.0  # normalize to [0,1] range

Run Code Online (Sandbox Code Playgroud)

当我在教程中使用简单的图像调整大小时,它可以工作:

#
import tensorflow as tf
#

img_raw = tf.io.read_file('./images/4c34476047bcbbfd10b1fd3342605659.jpeg/')

img_tensor = tf.image.decode_jpeg(img_raw, channels=3)

img_final = tf.image.resize(img_tensor, [192, 192])

img_final /= 255.0  #
Run Code Online (Sandbox Code Playgroud)

这是日志:

    img_final /= 255.0  # normalize to [0,1] range
  File ".../.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 876, in binary_op_wrapper
    return func(x, y, name=name)
  File ".../.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

4
推荐指数
1
解决办法
4421
查看次数

标签 统计

python ×2

tensorflow ×2

formatjs ×1

reactjs ×1