Skip to content

Commit 8efa34c

Browse files
committed
Make image converter built
Also add a test for including the image converter in a model.
1 parent 85eabbd commit 8efa34c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

keras_hub/src/layers/preprocessing/image_converter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ def __init__(
246246
self.antialias = antialias
247247
self.bounding_box_format = bounding_box_format
248248
self.data_format = standardize_data_format(data_format)
249+
self.built = True
249250

250251
@property
251252
def image_size(self):

keras_hub/src/layers/preprocessing/image_converter_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import pathlib
33

4+
import keras
45
import numpy as np
56
import pytest
67
import tensorflow as tf
@@ -28,6 +29,14 @@ def test_resize_dataset(self):
2829
batch = ds.batch(2).map(converter).take(1).get_single_element()
2930
self.assertAllClose(batch, tf.zeros((2, 4, 4, 3)))
3031

32+
def test_resize_in_model(self):
33+
converter = ImageConverter(height=4, width=4, scale=1 / 255.0)
34+
inputs = keras.Input(shape=(10, 10, 3))
35+
outputs = converter(inputs)
36+
model = keras.Model(inputs, outputs)
37+
batch = np.ones((1, 10, 10, 3)) * 255.0
38+
self.assertAllClose(model(batch), ops.ones((1, 4, 4, 3)))
39+
3140
def test_unbatched(self):
3241
converter = ImageConverter(
3342
image_size=(4, 4),

0 commit comments

Comments
 (0)