Reputation: 17
I'm passing a Numpy array, image, to 'process_image'. It is then processed, turned into a TensorSpec object with the dimensions and dtype required by the Tensorflow Hub model.
def image_preprocessing(image):
img = tf.convert_to_tensor(image, dtype=tf.float32)
img = tf.expand_dims(img, 0)
return tf.TensorSpec.from_tensor(img)
def process_image(image):
img = image_preprocessing(image)
model = generate_model()
hr_img = model(img, True)
return hr_img[0]
img: TensorSpec(shape=(1, 480, 640, 3), dtype=tf.float32, name=None)
The model is loaded from Tensorflow Hub;
import tensorflow_hub as hub
def generate_model():
SAVED_MODEL = 'https://tfhub.dev/captain-pool/esrgan-tf2/1'
model = hub.load(SAVED_MODEL)
return model
I then get this error code;
ValueError: Signature specifies 343 arguments, got: 342.
I've tried adding an additional argument (True), however it shows the exact same error as when I called model(img).
Would be thankful for any ideas.
Upvotes: 1
Views: 353
Reputation: 181
Use tf.cast
after tf.convert_to_tensor
Like: img = tf.cast(tf.convert_to_tensor(image), dtype=tf.float32)
Upvotes: 0
Reputation: 3414
Try following the example of usage at esrgan-tf2:
import tensorflow_hub as hub
import tensorflow as tf
model = hub.load("https://tfhub.dev/captain-pool/esrgan-tf2/1")
# To add an extra dimension for batch, use tf.expand_dims()
dummy_image = np.ones((1, 480, 640, 3)) # [batch_size, height, width, 3]
dummy_image = tf.cast(dummy_image, tf.float32)
super_resolution = model(dummy_image) # Perform Super Resolution here
Upvotes: -1