split crop model into backbone and head then predict, the res is not right #79
Description
Thank you for your outstanding work. I encountered some problems during my study and would like to ask you for advice.
your is right, split and saved is wrong
model_fold is download. pred is right
model = tf.saved_model.load(os.path.join(model_fold, "metrabs_rn18_y4"))
pred = model.estimate_poses(np.array(frames), boxes=np.array([[0,0,255,255]], dtype=np.float32))
wrong one, preds is img above. model_folder is I first split the crop model into two models: backbone and head. and saved
model_bbone_folder = r"----------\resnet18\bbone"
model_bbone = tf.saved_model.load(model_bbone_folder)
model_head_folder = r"---------------\resnet18\metrab_head"
model_head = tf.saved_model.load(model_head_folder)
feat = model_bbone(frames)
feat = feat.numpy()
feat = feat.astype(np.float16)
pred = model_head(feat, False)
1. split the crop model into two models: backbone and head.
2. save them into two models respectively.
3. two split models, load the overall model you provided, and verify it.
all the abs is 0.0
model_bbone_folder = r"-------------\resnet18\bbone"
model_bbone = tf.saved_model.load(model_bbone_folder)
for i in range(len(model_backbone_vars)):
string = model_backbone_vars[i].name + "-" + model_make.variables[i].name
abs = model_backbone_vars[i].numpy()-model_bbone.variables[i].numpy()
abs = np.max(abs)
print(string, abs)
4. loaded separately and inferred.
import cv2
import numpy as np
import tensorflow as tf
imgpath = r"C:\Users\20567\Desktop\ticao2.jpg"
frames = cv2.imread(imgpath)
frames = cv2.cvtColor(frames, cv2.COLOR_BGR2RGB)
frames= cv2.resize(frames, (256, 256))
plot_img = np.copy(frames)
frames = frames/ 255.
frames = frames[np.newaxis, :]
frames = frames.astype(np.float32)
model_bbone_folder = r"....................resnet18\bbone"
model_bbone = tf.saved_model.load(model_bbone_folder)
model_head_folder = r"........................\resnet18\metrab_head"
model_head = tf.saved_model.load(model_head_folder)
feat = model_bbone(frames)
feat = feat.numpy()
feat = feat.astype(np.float16)
pred = model_head(feat, False)
kpt2d = pred[0][0]
for i in range(kpt2d.shape[0]):
cv2.circle(plot_img, (int(kpt2d[i][0]), int(kpt2d[i][1])), 1, (0, 255, 0), -1)
cv2.imshow("", plot_img)
cv2.waitKey()
print(pred)
print("done")