Monaco12138 / SR_Tensorflow

This is a complete solution for deploying super-resolution models to Android devices, including model training, quantitative export, testing, and deployment
4 stars 1 forks source link

Convert to tflite #3

Open arianaa30 opened 2 months ago

arianaa30 commented 2 months ago

I trained a model with div2k dataset. I wanted to convert using your converter.py script. But it shows me this error:

Traceback (most recent call last):
  File "SR_Tensorflow\converter.py", line 27, in <module>
    model.load_weights(args.model_weight_path)
  File "anaconda3\Lib\site-packages\keras\src\utils\traceback_utils.py", line 70, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "anaconda3\Lib\site-packages\keras\src\saving\legacy\hdf5_format.py", line 816, in load_weights_from_hdf5_group
    raise ValueError(
ValueError: Layer count mismatch when loading weights from file. Model expected 4 layers, found 0 saved layers.

Do you happen to know what is going wrong?

Here is the model.zip. Here is the piece of converter.py. I trained a model on 270x480 inputs simply by running train.py. I then run python converter.py after training the model.

# args
parser = argparse.ArgumentParser()
parser.add_argument('--lr_path', default='./dataset/files_lr')
parser.add_argument('--hr_path', default='./dataset/files_hr')
parser.add_argument('--model_weight_path', default='./save/custom.h5')
parser.add_argument('--model_tmp_path', default='./save/')
parser.add_argument('--tflite_path', default='./save/quicsr_float32_test.tflite')
parser.add_argument('--scale', default=2)
args = parser.parse_args()

## model
num_filter = 32
num_res_blocks = 2
# model = edsr.EDSR(2, num_filter, num_res_blocks)
model = quicsr.QuicSR(2, num_filter, num_res_blocks)
model.load_weights(args.model_weight_path)
tf.saved_model.save(model, args.model_tmp_path)

## the model must be load like that instead of kears.models.Model(). 
model = tf.saved_model.load(args.model_tmp_path)

## setting fixed input size
h, w = 270, 480

scale = 2