Closed lyy-zz closed 3 years ago
Try to use the following codes to load keras model: import tensorflow as tf
model = tf.keras.models.load_model(model_path, custom_object={'tf': tf})
The solution you provided can load the model and infer normally, thank you
https://www.tensorflow.org/api_docs/python/tf/saved_model/load
Hi I am also trying to use the pretrained pb to make prediction.
the code to make prediction is:
pb_file_path = './experiment/base7_D4C28_bs16ps64_lr1e-3/best_status'
image_path = './test_images/butterfly.png'
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image/255, (256,256))
input_data = image[np.newaxis].astype(np.float32)
model = tf.saved_model.load(pb_file_path)
output = model(input_data)`
And I got the result as shown below. The generated image seems a bit weird. For example, there are many mosaic pixels in the bottom left part.
Could you help me figure out why may cause this problem? I also attached butterfly image if you need. Thank you in advance.
Hi I am also trying to use the pretrained pb to make prediction.
the code to make prediction is:
pb_file_path = './experiment/base7_D4C28_bs16ps64_lr1e-3/best_status' image_path = './test_images/butterfly.png' image = cv2.imread(image_path) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = cv2.resize(image/255, (256,256)) input_data = image[np.newaxis].astype(np.float32) model = tf.saved_model.load(pb_file_path) output = model(input_data)`
And I got the result as shown below. The generated image seems a bit weird. For example, there are many mosaic pixels in the bottom left part.
Could you help me figure out why may cause this problem? I also attached butterfly image if you need. Thank you in advance.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
Thank you for your quick reply.
I encountered some errors that are likely due to the python/tf version inconsistent. Could you share your python and tf version info?
Python version: 3.7.10 Tensorflow version: 2.4.1 And conda environment file (tf.yaml) is provided in the github repository, you can check more details about package versions. ------------------ Original ------------------ From: @.>; Date: Fri, Jun 18, 2021 12:00 PM To: @.>; Cc: @.>; @.>; Subject: Re: [NJU-Jet/SR_Mobile_Quantization] how to evaluate by pretrained pb? (#11)
Thank you for your quick reply.
I encountered some errors that are likely due to the python/tf version inconsistent. Could you share your python and tf version info?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
I know it has been a while, but can someone please share the evaluation snippet to test the .pb (or .tflite, whatever available) model?
I'm using this snippet (also tried the revisions suggested above), but didn't succeed :(
import tensorflow as tf
import cv2
import numpy as np
model_dir = './experiment/base7_D4C28_bs16ps64_lr1e-3/best_status/saved_model'
image_path = 'sample.png'
image = cv2.imread(image_path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image = cv2.resize(image, (256, 256))
input_data = image[np.newaxis].astype(np.float32)
model = tf.keras.models.load_model(model_dir)
output = model.predict(input_data)
output = cv2.cvtColor(output[0], cv2.COLOR_RGB2BGR)
cv2.imshow('hr', output)
cv2.waitKey(0)
cv2.destroyAllWindows()
I try to evaluate with pre-training pb, but got an error I rarely use tf2.0, trying to read the document or google did not solve the problem Do you have any solutions? Thank you
code example
error
TypeError: signature_wrapper(*, input_1) missing required arguments: input_1