Skip to content

local variable 'is_collect' referenced before assignment #9

@Albert950207

Description

@Albert950207

Hi,

I got a error when I run the command:

mlagents-learn trainer_config.yaml --run-id=test_run --train --slow

The error is :

File "/home/bohan/Downloads/ml-agents/ml-agents/mlagents/trainers/models.py", line 595, in create_dc_actor_critic
output = tf.concat([output_pre,is_collect],1)
UnboundLocalError: local variable 'is_collect' referenced before assignment

I checked the python file and found:

output_pre = output[:,0:2]
if self.with_heuristics:
is_collect = self.is_collect_tf(self.fused_visual_in)
output = tf.concat([output_pre,is_collect],1)
self.output = tf.identity(output, name="action")

In this training command, the parameter heuristics is false so the value of is_collect wont be given, which leads to the error. I dont know what is_collect should be if heuristics is false. Could you please help me ?

By the way, after I load the project in unity, there are no any compile errors but once I run the training command, there are two errors:

  1. Instance of CoreBrainInternal couldn't be created. The the script class needs to derive from ScriptableObject.
    UnityEngine.ScriptableObject:CreateInstance (string)
    MLAgents.Brain:UpdateCoreBrains () (at Assets/ML-Agents/Scripts/Brain.cs:144)
    MLAgents.Brain:InitializeBrain (MLAgents.Academy,MLAgents.Batcher) (at Assets/ML-Agents/Scripts/Brain.cs:206)
    MLAgents.Academy:InitializeEnvironment () (at Assets/ML-Agents/Scripts/Academy.cs:288)
    MLAgents.Academy:Awake () (at Assets/ML-Agents/Scripts/Academy.cs:227)

2.UnityAgentsException: The Communicator was unable to connect. Please make sure the External process is ready to accept communication with Unity.
MLAgents.Batcher.SendAcademyParameters (MLAgents.CommunicatorObjects.UnityRLInitializationOutput academyParameters) (at Assets/ML-Agents/Scripts/Batcher.cs:83)
MLAgents.Academy.InitializeEnvironment () (at Assets/ML-Agents/Scripts/Academy.cs:320)
MLAgents.Academy.Awake () (at Assets/ML-Agents/Scripts/Academy.cs:227)

So far, I just tried the training part 1 and didn't put the pre-trained model into unity. Are these two errors only related to inference part?

Unity Version: 2020.3.6f1
Unity machine OS + version: Ubuntu 20.04

Thanks!
Albert

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions