Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Trying Build And Run Project with already trained Ml Agent

Discussion in 'ML-Agents' started by ognegrum91, Sep 30, 2020.

  1. ognegrum91

    ognegrum91

    Joined:
    May 2, 2020
    Posts:
    7
    I have a problem with running a project, which contains an Already Trained ML Agent. When I run the EXE file the game starts but the Agent just stays there and its not trying to complete its goal. In the Editor everything is fine. When I press the play button the agent with already attached trained brain starts to fulfil its goal and it works perfectly. I would like to use this Trained Agent in a future game. Thanks in Advanced for your help !
     
  2. henrypeteet

    henrypeteet

    Unity Technologies

    Joined:
    Aug 19, 2020
    Posts:
    37
    Hi, thanks for reaching out. Can you supply some additional information to help us narrow the problem down?
    1. Is this is one of the example environments or in your own custom environment? If your own then can you roughly describe what you are training the agent to do?
    2. What version of mlagents are you using?
    3. What version of unity are you using?
    4. What platform (Mac, PC, Linux) are you developing on?
    Thanks so much for your interest :)
     
  3. ognegrum91

    ognegrum91

    Joined:
    May 2, 2020
    Posts:
    7
    @henrypeteet Hello :) . I am training my own agent. Its should always try to reach the green square, to jump over the white wall and to avoid going down to the Red Dead zone. I am currently working on MAC and Im using the latest versions of Unity 2020 and the latest Preview of ML Agent - 1.4.0. On the Editor everything is fine. When I add trained brain to the bunny its performing very well and it reaches its goal 95-99% of the time. When I perform training in external window it also goes really well, beside the problem with the very little initial window size. However, when I decide to Build And Run the scene, Run it outside of the Unity Editor not for training, but for seeing how well it does when its already trained, the Agent stays without moving. Its like it does not have any attached logic - like when you run scene, but without any script that should apply the actions.

    The picture below has taken when the bunny is using its trained brain and tries to achieve its goal

    upload_2020-10-2_15-9-14.png
     
  4. henrypeteet

    henrypeteet

    Unity Technologies

    Joined:
    Aug 19, 2020
    Posts:
    37
    Thanks for the explanation and screenshot.

    If you set the Behavior Parameters --> Behavior Type to "Inference Only" and click play in the editor do you get the same bad result? If the agent doesn't reflect the trained behavior then it is likely you have the wrong neural net dragged onto your Behavior Parameters --> Model. Make sure to drag the item from your results/<your_run>/<your_behavior_name> onto that field.

    If this is not the issue then did you happen to adjust the engine's timescale value?

    If neither of these help this would likely be categorized as a bug and we would want to file it on the GitHub page.
     
  5. ognegrum91

    ognegrum91

    Joined:
    May 2, 2020
    Posts:
    7
    Hello @henrypeteet . Thanks for the suggestions. In the editor in inference mode everything is fine. I will ty to play with the timescale and i will share with you some results. In fact, when I click play in the Editor everything works really good. When the behaviour in inference and the nn file is attached also everything works great.
    This is the behaviour of my agent with other two components - Model Overrider and Decision Requester. Thanks again for your help. I will experiment with the timescale and I will share with you some results.
     

    Attached Files:

  6. ognegrum91

    ognegrum91

    Joined:
    May 2, 2020
    Posts:
    7
    @henrypeteet There is an Error. I saw it when I build Debug build. I am posting an image, some logs and my build settings. I did not change the timescale and I have tried both with and without 'ENABLE_TENSORFLOW' and it all remains the same. It looks like it can not find a DllFile. I will do some investigation

    Code (Boo):
    1. DllNotFoundException: macblas
    2.   at (wrapper managed-to-native) Unity.Barracuda.MacBLAS.macsgemm(single*,int,int,single*,int,int,single*,int,int,int,bool,bool)
    3.   at Unity.Barracuda.MacBLAS.SGEMM (System.Single* Ap, System.Int32 AN, System.Int32 AM, System.Single* Bp, System.Int32 BN, System.Int32 BM, System.Single* Cp, System.Int32 CN, System.Int32 CM, System.Int32 bs, System.Boolean transposeA, System.Boolean transposeB) [0x00001] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Plugins/OSX/MacBLAS.cs:39
    4.   at Unity.Barracuda.UnsafeArrayCPUOps.Dense (Unity.Barracuda.Tensor X, Unity.Barracuda.Tensor W, Unity.Barracuda.Tensor B, Unity.Barracuda.Layer+FusedActivation fusedActivation) [0x00132] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/BarracudaUnsafeArrayCPU.cs:1255
    5.   at Unity.Barracuda.GenericWorker+<StartManualSchedule>d__29.MoveNext () [0x002ed] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/GenericWorker.cs:203
    6.   at Unity.Barracuda.GenericWorker.Execute () [0x0000c] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/GenericWorker.cs:118
    7.   at Unity.Barracuda.GenericWorker.Execute (System.Collections.Generic.IDictionary`2[TKey,TValue] inputs) [0x0003c] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Core/Backends/GenericWorker.cs:106
    8.   at Unity.MLAgents.Inference.ModelRunner.DecideBatch () [0x000f4] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.ml-agents@1.4.0-preview/Runtime/Inference/ModelRunner.cs:174
    9.   at Unity.MLAgents.Policies.BarracudaPolicy.DecideAction () [0x00001] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.ml-agents@1.4.0-preview/Runtime/Policies/BarracudaPolicy.cs:66
    10.   at Unity.MLAgents.Agent.DecideAction () [0x0002c] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.ml-agents@1.4.0-preview/Runtime/Agent.cs:1291
    11.   at (wrapper delegate-invoke) <Module>.invoke_void()
    12.   at Unity.MLAgents.Academy.EnvironmentStep () [0x000bd] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.ml-agents@1.4.0-preview/Runtime/Academy.cs:542
    13.   at Unity.MLAgents.AcademyFixedUpdateStepper.FixedUpdate () [0x00001] in /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.ml-agents@1.4.0-preview/Runtime/Academy.cs:35
    14.  
    15. (Filename: /Users/ivaylodimitrov/Desktop/Unity3D/SeekGoalMLAgent/Library/PackageCache/com.unity.barracuda@1.1.1-preview/Barracuda/Runtime/Plugins/OSX/MacBLAS.cs Line: 39)
     

    Attached Files:

    Last edited: Oct 4, 2020
  7. henrypeteet

    henrypeteet

    Unity Technologies

    Joined:
    Aug 19, 2020
    Posts:
    37
    Thanks for the updates.

    Hmm, does the resolution in https://github.com/Unity-Technologies/ml-agents/issues/2735 help at all with the last bug?

    With regards to the overall problem is there a reason you need the Model Overrider, if you want to use the model from the game you shouldn't need it IIUC? If you just remove it or disable it does inference in the built executable work?
     
  8. ognegrum91

    ognegrum91

    Joined:
    May 2, 2020
    Posts:
    7
    @henrypeteet Thanks ! No, the suggested issue is connected to the main Unity Repository. My project is separated. However, thanks to your suggestion to read the upper thread in GitHub I was able to fix my own problem. Here are two images. The problem was The Build Architecture - it seems that the Intel 64 Works Great for me. Its Perfect ! But previosly I was using Intel 64 + Apple silicon. I am not an expert in this but it seems that MAC OS build architectures have something to do with how the OS after build and run deals with the produced Application. Unfortunately, the produced build for MAC OS is a single Application file and does not give me much information. If I can help with anything for investigating why Intel 64 + Apple Silicon architecture causes this problem, feel free to contact me :) . Thanks for the support. Kind Regards and Great Job with the Ml Agent. I like it a lot ! Have a Great One ! :)
     

    Attached Files:

  9. henrypeteet

    henrypeteet

    Unity Technologies

    Joined:
    Aug 19, 2020
    Posts:
    37
    Glad it worked out. Thanks.