Search Unity

Output of .nn model

Discussion in 'ML-Agents' started by Procuste, Feb 22, 2020.

  1. Procuste

    Procuste

    Joined:
    Feb 10, 2020
    Posts:
    12
    Hello,

    In my attempt to training my own RL algorithm in Python, I must create a model that takes as input the agent observation and outputs the action(s) that it believes is the best.
    However, what output exactly does the Tensorflow model (and thus the .nn model) needs to have in order to be « understood » in Unity ? is it the probabilities of each actions ? The log probs ? The actions selected directly?
    I have searched through the docs but didn’t find the answer.

    Thank you.
     
    unity_-DoCqyPS6-iU3A likes this.
  2. jeffrey_unity538

    jeffrey_unity538

    Unity Technologies

    Joined:
    Feb 15, 2018
    Posts:
    59
    Hi Procuste - the .nn files are Tensorflow model files and more info can be found on the tensorflow site. However, let me know if you can elaborate in case I am missing some context.
     
  3. Procuste

    Procuste

    Joined:
    Feb 10, 2020
    Posts:
    12
    Thank you for your response.
    I was wondering about the exact output shapes (as well as inputs) that the Tensorflow model should have in order to be, once converted to a .nn file, correctly interpreted by Unity. After digging through the code of mlagents-learn, here is what I found for those interested :

    As inputs, the model should have :
    • a placeholder named "vector_observation" of shape [None, vec_obs_size]
    • a placeholder named "action_masks" of shape [None, num_act], where num_act is the total number of actions possible (every branch included)
    As output, the model should have :
    • a node called "action" which contains the log probs for each actions
    Also, the model should contains the following constants :
    • "version_number", of type tf.int32
    • "memory_size" of type tf.int32
    • "is_continuous_control" of type tf.int32
    • "action_output_shape" of type tf.int32 (total number of actions possible, every branch included)
    If you want an example of a simple model built with Tensorflow, then converted to a .nn file using the script tensorflow-to-barracuda.py, here's a simple Jupyter notebook : https://github.com/Procuste34/Unity...ow-to-barracuda/tensorflowModelCreation.ipynb
     
  4. vincentgao88

    vincentgao88

    Unity Technologies

    Joined:
    Feb 7, 2018
    Posts:
    21
    Hi Procuste,

    All of the .nn models are understood by Barrcuda as long as you can use tensorflow-to-barracuda.py to convert it. And you should be able to use all of them in Unity. However not all of the .nn models are understood by ml-agents C# code. Are you trying to create some .nn model that are understood by ml-agents C# side code?
     
  5. Procuste

    Procuste

    Joined:
    Feb 10, 2020
    Posts:
    12
    No, I was trying (and succedeed) to create .nn model that can be understood by Unity directly. I found out the different necessary nodes that need to be in the model to be understood by Unity (elsewise you get errors in Unity).
     
  6. vincentgao88

    vincentgao88

    Unity Technologies

    Joined:
    Feb 7, 2018
    Posts:
    21
    Nice, glad it worked.
     
    Procuste likes this.
  7. ShayanRiyaz

    ShayanRiyaz

    Joined:
    Mar 10, 2020
    Posts:
    3
    Hi Procuste,

    Can you please help me find the resource regarding the necessary nodes or just tips on how to create a model suitable for a .nn file and Unity. That would be of great help.
     
  8. OleguerCanal

    OleguerCanal

    Joined:
    Jul 21, 2015
    Posts:
    7
    I am also interested, I tried to train a model using stable baselines but I didn't manage to successfully convert the tensorflow graph into a .nn using tensorflow-to-barracuda.py. I always get errors.