J'ai testé OTBTF (tf 2) sur un modèle sauvegardé en mode compat v1. Le mécanisme utilisant bundle.GetSignatures().at("serving_default").inputs() semble fonctionner pas trop mal.
Là j'ai juste une erreur car certains tensors sont en INT16. Par exemple :
------------------------------------------------- PrintDebugString --------------------------------name: "tower_0/s2_tp1:0"dtype: DT_INT16tensor_shape { dim { size: -1 } dim { size: 256 } dim { size: 256 } dim { size: 4 }}
Du coup le type INT16 n'est pas géré dans otbTensorflowCopyUtils :
RuntimeError: Exception thrown in otbApplication Application_ExecuteAndWriteOutput: /src/otb/otb/Modules/Remote/otbtf/include/otbTensorflowCopyUtils.cxx:108:itk::ERROR: TF DataType 17 not currently implemented !
A voir si on cast tout en INT32 ou autre, j'ai pas trop réfléchi là dessus !
By Narcon Nicolas on 2021-08-24T18:03:17 (imported from GitLab)
J'ai 2 problèmes avec les saved_model du dossier test.
En lançant saved_model_cli show --dir models/model2 --all
MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:MetaGraphDef with tag-set: 'train' contains the following SignatureDefs:signature_def['model']: The given SavedModel SignatureDef contains the following input(s): inputs['x1:0'] tensor_info: dtype: DT_FLOAT shape: (-1, -1, -1, 4) name: x1:0 inputs['x2:0'] tensor_info: dtype: DT_FLOAT shape: (-1, -1, -1, 1) name: x2:0 inputs['y:0'] tensor_info: dtype: DT_INT32 shape: (-1, -1, -1, 1) name: y:0 The given SavedModel SignatureDef contains the following output(s): outputs['features:0'] tensor_info: dtype: DT_FLOAT shape: (-1, 128) name: features:0 outputs['prediction:0'] tensor_info: dtype: DT_INT64 shape: (-1) name: prediction:0 Method name is: tensorflow/serving/predict
1er problème
Le tag-set 'serve' ne contient rien, contrairement à tous les modèles TF2 et TF2 compat v1 (et certainement TF1 je pense). Ce 'serve' est celui qui est utilisé lors du chargement du modèle dans otbTensorflowGraphOperations.cxx
On met un argument optional tagserve dans l'appli TensorFlowModelServe ?
TensorFlowModelTrain
Voir s'il faut modifier l'appli pour que le tag-set soit 'serve' lorsqu'on sauvegarde le modèle
2ème problème
J'ai remplacé kSavedModelTagServe en dur par 'train' pour voir si le 1er problème pouvait facilement être réglé. Cela résoud en partie le problème, on arrive bien à accéder aux inputs/outputs mais j'ai une segmentation fault lors du RunSession. Est ce qu'il y a une différence entre le graph 'serve' et le graph 'training' ? Sinon, je remarque que la shape de outputs['prediction:0'] est (-1), c'est normal ?
EDIT: j'avais un bout de code obsolète qui faisait planter, ça semble marcher maintenant ! je vais comparer avec les baselines
By Narcon Nicolas on 2021-08-27T16:24:56 (imported from GitLab)
Je ne pense pas que ce soit possible depuis le C++.
Toutes les méthodes Load... demandent une liste de tag-sets. Il y a bien une méthode ReadSavedModel dans tensorflow/cc/saved_model/reader.cc mais ça ne retrouve pas les tags.
D'ailleurs à un endroit dans le code, il y a:
"Could not find meta graph def matching supplied tags: { ",absl::StrJoin(tags," ")," }. To inspect available tag-sets in the SavedModel, please ""use the SavedModel CLI: `saved_model_cli`"));
Donc je pense qu'on va suivre ce conseil, et permettre optionellement à l'utilisateur de spécifier ses tag-sets (qu'il aura trouvé si besoin en utilisant saved_model_cli)
By Narcon Nicolas on 2021-08-30T18:20:12 (imported from GitLab)
on va suivre ce conseil, et permettre optionnellement à l'utilisateur de spécifier ses tag-sets (qu'il aura trouvé si besoin en utilisant saved_model_cli)
Ok. On documentera cela un peu dans la description du nouveau paramètre optionnel
By Cresson Remi on 2021-08-30T18:20:12 (imported from GitLab)