def get_model(id_): m = Model(model_id=id_) # noinspection PyBroadException try: # make sure the model is is valid # noinspection PyProtectedMember m._get_model_data() return m except Exception: pass
def _get_output_models(task): # type: ("clearml.Task") -> ModelsList # noqa: F821 res = task.send( models.GetAllRequest( task=[task.id], order_by=["created"], only_fields=["id"] ) ) ids = [m.id for m in res.response.models or []] + list(task.output_models_id.values()) # remove duplicates and preserve order ids = list(OrderedDict.fromkeys(ids)) id_to_name = ( {x.model: x.name for x in task.data.models.output} if Session.check_min_api_version("2.13") else {} ) def resolve_name(index, model_id): return id_to_name.get(model_id, "Output Model #{}".format(index)) from clearml.model import Model output_models = OrderedDict( (resolve_name(i, m_id), Model(model_id=m_id)) for i, m_id in enumerate(ids) ) return ModelsList(output_models)