Use saved model in plugin recipe

Solved!
Franck
Level 2
Use saved model in plugin recipe

Hello everyone,

 

I can't figure out how to use a saved model in a custom python plugin recipe.

- If I try to pass it as an input (declared in the recipe.json file), I can't select it when creating the recipe (I have something like "Saved model are not accepted for this input").

- If I try to pass it as a parameter, either as a STRING or a SAVED_MODEL. I have the python error: "Saved model MODEL_NAME cannot be used : declare it as input or output of your recipe"

- Even when trying to load it directly by hard-coding the name in the python code, same error as with a parameter.

 

Am I missing something ?

Thanks for your help.

Franck

0 Kudos
1 Solution
AgatheG
Dataiker

You'll need indeed to use dataiku.customrecipe.get_input_names_for_role

The method takes one argument, role, in which you should put the name you defined in recipe.json for the input you want to retrieve.

Beware that the method returns a list, as you may have NARY inputs; so you should take the element at index 0 if you have a UNARY input.

Basically, something like this should allow you to retrieve your model id:

from dataiku.customrecipe import get_input_names_for_role

saved_model_id = get_input_names_for_role(YOUR_INPUT_NAME)[0]

 

Hope this helps as well ๐Ÿ™‚

View solution in original post

0 Kudos
4 Replies
AgatheG
Dataiker

Hi Franck!

The way to go is indeed by declaring your saved model as an input of your recipe within your recipe.json file. You'll need to add a field acceptsSavedModel for DSS to understand that saved models are the expected input:

"inputRoles": [
  ...
  {
            "name": ...,
            "label": ...,
            "description": ...,
            "required": ...,
            "arity": ...,
            "acceptsDataset": false,
            "acceptsSavedModel": true
  },
...]

 

I also set acceptsDataset to false in my above example to ensure only saved models are accepted.

 

Hope this helps!

 

Agathe

0 Kudos
Franck
Level 2
Author

Hi Agathe,

 

I tried this way but I used "acceptsModel" instead, as I couldn't find any doc on this possible keys we can use...

Thanks a lot for your help ๐Ÿ™‚

 

Now I am able to pass it as input, but still, how do I load it from the python code ? The only function that I could find to interact with the json file are here, and it looks like none would do the job https://doc.dataiku.com/dss/latest/python-api/plugins/custom_recipes.html

If I try to get the model name and then open it with the Dataiku module, like we would do with a dataset, I still get the error.

 

Thanks

Franck

 

0 Kudos
AgatheG
Dataiker

You'll need indeed to use dataiku.customrecipe.get_input_names_for_role

The method takes one argument, role, in which you should put the name you defined in recipe.json for the input you want to retrieve.

Beware that the method returns a list, as you may have NARY inputs; so you should take the element at index 0 if you have a UNARY input.

Basically, something like this should allow you to retrieve your model id:

from dataiku.customrecipe import get_input_names_for_role

saved_model_id = get_input_names_for_role(YOUR_INPUT_NAME)[0]

 

Hope this helps as well ๐Ÿ™‚

0 Kudos
Franck
Level 2
Author

Ok, I was not considering the output of get_input_names_for_role as a list.

It's working now, thanks a lot