Search Unity

Bug Getting "Traceback (most recent call last)" error with ML Agents

Discussion in 'ML-Agents' started by tobias-htl-wo, Jun 13, 2023.

  1. tobias-htl-wo

    tobias-htl-wo

    Joined:
    Nov 13, 2022
    Posts:
    1
    Hi, I wanted to try something new and found this tutorial (
    ).
    So i followed it until the step where you run the command "mlagents-learn". Until there everything worked just like in the tutorial.
    Here I am getting this big error :


    I have tried "pip install protobuf==3.20" and "pip3 install --upgrade protobuf==3.20.0" and "pip install importlib-metadata==4.8" but i always get the same errors, sometimes even a bit more. Also i installed https://learn.microsoft.com/en-us/c...svc-170#visual-studio-2015-2017-2019-and-2022 but that didnt help either.
    I am using unity 2021.3.14f1 and Python 3.7.9. The torch version should be 1.7.1.
    Thanks for any help!!
     
  2. QuinnCG

    QuinnCG

    Joined:
    Jan 30, 2020
    Posts:
    6
    I'm currently having the same issue. One thing to note is you have to type "mlagents-learn --force" to overwrite the existing data; even though it failed to train before. I assume, like me, once you do this you'll continue to get a traceback error.

    I also installed visual studio redistributables 2015-2022.

    I was initially following the same tutorial but have turned to a multitude of other sources to try and get it fixed. I've gotten close but still run into errors. I've tried the whole process from scratch on Python 3.7, 3.8, and 3.9.

    I saw some recommendations to downgrade importlib-metadata (type "pip install importlib-metadata==4.8") to version 4.4 or 4.8; supposedly this is because the ml agents package doesn't work with the newer versions of importlib. Version 4.4 wasn't available but 4.8 was and it got me past the error the OP is having and onto a new one.

    The first image below is what I managed to get after downgrading the importlib. Before I was having the same issue as the OP (after using "mlagents-learn --force"). The second image is the error that occurred when I play the editor.

    The code below is what I have my agent set up for and the Debug.Log logs only 0s. The third image below shows the inspector's view of the agent for reference.

    Code (CSharp):
    1. using Unity.MLAgents;
    2. using Unity.MLAgents.Actuators;
    3. using UnityEngine;
    4.  
    5. public class MoveToGoalAgent : Agent
    6. {
    7.     [SerializeField]
    8.     private float MoveSpeed = 5f;
    9.  
    10.     [SerializeField]
    11.     private Transform GoalTransform;
    12.  
    13.     public override void OnActionReceived(ActionBuffers actions)
    14.     {
    15.         Debug.Log(actions.DiscreteActions[0]);
    16.     }
    17. }
    18.  
    I got this far using:
    • Unity 2022.2.19
    • Python 3.7.9
    • Torch 1.7.1
    • ML Agents 0.29.0

    1.png 2.png
     

    Attached Files:

    Last edited: Jun 15, 2023
  3. QuinnCG

    QuinnCG

    Joined:
    Jan 30, 2020
    Posts:
    6
    Turns out the issue I had after downgrading the importlib was just an error in my AI setup; I had set observations to 0.
    tobias-htl-wo You should try running the command "pip install importlib-metadata==4.8". I did this in the virtual environment after installing everything including ml agents and it took me from getting your type of errors to not getting errors. I'm using the same version of everything else as you. Hope it helps you.