【问题标题】:In Python, getting size of images tensorflow2 model trained on?在 Python 中,获取 tensorflow2 模型训练的图像大小?
【发布时间】:2022-01-12 18:02:38
【问题描述】:

我正在使用以下方法加载模型:

m = tf.saved_model.load(str(model_path))

我希望能够获取有关模型训练的图像大小的信息,以便调整我想要推断的新图像的大小。

我知道我可以使用 keras 模型:

shape_0 = m.layers[0].output_shape
input_height = shape_0[1]
input_width= shape_0[2]

获取训练图像的输入高度和宽度。

是否有类似的命令可以从 tensorflow2 模型中获取这些值?

【问题讨论】:

  • 好的,非常感谢。

标签: python tensorflow keras deep-learning tensorflow2.0


【解决方案1】:

使用model.signatures['serving_default']:

import tensorflow as tf

model = tf.keras.Sequential([
  tf.keras.layers.Conv2D(16, 3, padding='same', activation='relu', input_shape=(128, 128, 3)),
  tf.keras.layers.MaxPooling2D(),
  tf.keras.layers.Conv2D(32, 3, padding='same', activation='relu'),
  tf.keras.layers.MaxPooling2D(),
  tf.keras.layers.Conv2D(64, 3, padding='same', activation='relu'),
  tf.keras.layers.MaxPooling2D(),
  tf.keras.layers.Flatten(),
  tf.keras.layers.Dense(128, activation='relu'),
  tf.keras.layers.Dense(5)
])
tf.saved_model.save(model, '/content/model')
imported_model = tf.saved_model.load('/content/model')

print(imported_model.signatures['serving_default'])
INFO:tensorflow:Assets written to: /content/model/assets
ConcreteFunction signature_wrapper(*, conv2d_3_input)
  Args:
    conv2d_3_input: float32 Tensor, shape=(None, 128, 128, 3)
  Returns:
    {'dense_4': <1>}
      <1>: float32 Tensor, shape=(None, 5)

【讨论】:

    猜你喜欢
    • 2019-10-05
    • 2020-05-27
    • 2020-01-11
    • 2022-12-29
    • 2018-02-20
    • 2020-03-24
    • 2021-09-06
    • 2018-06-04
    • 1970-01-01
    相关资源
    最近更新 更多