| import tensorflow as tf |
| from pathlib import Path |
| import numpy as np |
| from PIL import Image |
|
|
| model_path = 'saved_model_age_regressor' |
| img_path = Path('data/UTKFace/53_1_1_20170110122449716.jpg.chip.jpg') |
| print('Model path:', model_path, flush=True) |
| print('Image path:', img_path, flush=True) |
|
|
| m = tf.keras.models.load_model(model_path, compile=False) |
| print('Loaded model type:', type(m), flush=True) |
| try: |
| m.summary() |
| except Exception as e: |
| print('model.summary failed:', e, flush=True) |
|
|
| img = Image.open(img_path).convert('RGB').resize((224,224)) |
| arr = np.array(img, dtype=np.float32)/255.0 |
| x = np.expand_dims(arr, 0) |
| print('Input shape:', x.shape, flush=True) |
| pred = m.predict(x) |
| print('Raw prediction output:', pred, 'shape:', getattr(pred, 'shape', None), flush=True) |
| try: |
| print('Predicted age:', float(pred.flatten()[0]), flush=True) |
| except Exception as e: |
| print('Error converting prediction to float:', e, flush=True) |
|
|