Unity-Technologies / ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
https://unity.com/products/machine-learning-agents
Other
16.93k stars 4.13k forks source link

The type or namespace name 'Barracuda' does not exist in the namespace 'Unity' #6023

Closed benzhangdragonplus closed 7 months ago

benzhangdragonplus commented 9 months ago

Describe the bug After importing the ML Agents package, there is an issue with the namespace prompt: “com.unity.ml-agents\Runtime\Policies\BehaviorParameters.cs(1,13): error CS0234: The type or namespace name 'Barracuda' does not exist in the namespace 'Unity' (are you missing an assembly reference?)“

“com.unity.ml-agents\Runtime\Policies\BehaviorParameters.cs(105,16): error CS0246: The type or namespace name 'NNModel' could not be found (are you missing a using directive or an assembly reference?)”

“com.unity.ml-agents\Runtime\Policies\BehaviorParameters.cs(98,9): error CS0246: The type or namespace name 'NNModel' could not be found (are you missing a using directive or an assembly reference?)”

Environment (please complete the following information):

miguelalonsojr commented 9 months ago

Did you upgrade from a previous version of MLA? If so, It may be that you need to delete your package cache as it might be causing conflicts. Barracuda was deprecated with the last release. Seems like you have an old version of MLA that is causing conflicts. You can see here that there's no mention of Barracuda in the BehaviorParameters script: https://github.com/Unity-Technologies/ml-agents/blob/develop/com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs

benzhangdragonplus commented 9 months ago

Did you upgrade from a previous version of MLA? If so, It may be that you need to delete your package cache as it might be causing conflicts. Barracuda was deprecated with the last release. Seems like you have an old version of MLA that is causing conflicts. You can see here that there's no mention of Barracuda in the BehaviorParameters script: https://github.com/Unity-Technologies/ml-agents/blob/develop/com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs

Thank you for your reply!!! Yes, the source code does not have Barracuda, but when importing the 3D Balance Ball example, the package has the Barracuda option. Do I need to uncheck it? like this: 1701001741997

benzhangdragonplus commented 9 months ago

Did you upgrade from a previous version of MLA? If so, It may be that you need to delete your package cache as it might be causing conflicts. Barracuda was deprecated with the last release. Seems like you have an old version of MLA that is causing conflicts. You can see here that there's no mention of Barracuda in the BehaviorParameters script: https://github.com/Unity-Technologies/ml-agents/blob/develop/com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs

Thank you for your reply!!! Yes, the source code does not have Barracuda, but when importing the 3D Balance Ball example, the package has the Barracuda option. Do I need to uncheck it? like this: 1701001741997

By the way, when I import the examples, the source code content will also change and Barracuda will be automatically added 1701001854951

miguelalonsojr commented 9 months ago

Oh, I see what the issue is. The 3DBall example package is stale and needs to be updated. I can take care of that. Thanks for submitting the issue.

chenjianbochen commented 9 months ago

I've met the same problem, and confused the whole day (cry~).

Hope I've seen this issue early. Anyway, looking for your update~~

miguelalonsojr commented 9 months ago

I've met the same problem, and confused the whole day (cry~).

Hope I've seen this issue early. Anyway, looking for your update~~

Thanks for your understanding. I'm the only maintainer of ML-Agents currently, so things are bound to slip through the cracks. I should have this update done sometime this week. Thanks for reaching out.

kkkkkom333 commented 9 months ago

I had the same issue. But @benzhangdragonplus, did uncheck Barracuda package resolve the issue?

For me I think what I did was to install the Barracuda 3.0.0 from package manager and remove the ml-agents.extensions package. Not sure which of those actually helped, but it got me moving forward.

benzhangdragonplus commented 9 months ago

I had the same issue. But @benzhangdragonplus, did uncheck Barracuda package resolve the issue?

For me I think what I did was to install the Barracuda 3.0.0 from package manager and remove the ml-agents.extensions package. Not sure which of those actually helped, but it got me moving forward.

replay: Unchecking doesn't work either. You can use the release 20 version directly, and there is currently no problem. Secondly, the reason for the error is that the 3DBall example has not been updated, while other examples such as match-3 have no issues

benzhangdragonplus commented 9 months ago

Oh, I see what the issue is. The 3DBall example package is stale and needs to be updated. I can take care of that. Thanks for submitting the issue.

Thanks for your hard work ^_^

13Flo commented 9 months ago

Same issue here, waiting for the fix!

miguelalonsojr commented 9 months ago

Fix: https://github.com/Unity-Technologies/ml-agents/pull/6030 Should be merged into develop today.

Lokiare commented 9 months ago

I'm getting the same issue and I've followed the instructions to install everything successfully. The errors don't show up until you install the ball sample, but they are in a different directory (see first image of issues thread). I'm on: Unity 2022.3.6f1 Windows 11

Lokiare commented 9 months ago

I re-installed everything and changed the numpy==1.23.0 line 63 in the setup.py file and then downloaded your updated sample and everything works until I get to the training phase of the example. It starts working fine, but then it looks like Unity locks up and the command line gives errors saying its waiting on Unity. The output is: (mlagents) D:\Users\lokia\Documents\Unity\ML Agents 02 Prototype\ml-agents>mlagents-learn config/ppo/3DBall.yaml --run-id=first3DBallRun --force D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\torch__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ..\torch\csrc\tensor\python_tensor.cpp:453.) _C._set_default_tensor_type(t)

        ┐  ╖
    ╓╖╬│╡  ││╬╖╖
╓╖╬│││││┘  ╬│││││╬╖

╖╬│││││╬╜ ╙╬│││││╖╖ ╗╗╗ ╬╬╬╬╖││╦╖ ╖╬││╗╣╣╣╬ ╟╣╣╬ ╟╣╣╣ ╜╜╜ ╟╣╣ ╬╬╬╬╬╬╬╬╖│╬╖╖╓╬╪│╓╣╣╣╣╣╣╣╬ ╟╣╣╬ ╟╣╣╣ ╒╣╣╖╗╣╣╣╗ ╣╣╣ ╣╣╣╣╣╣ ╟╣╣╖ ╣╣╣ ╬╬╬╬┐ ╙╬╬╬╬│╓╣╣╣╝╜ ╫╣╣╣╬ ╟╣╣╬ ╟╣╣╣ ╟╣╣╣╙ ╙╣╣╣ ╣╣╣ ╙╟╣╣╜╙ ╫╣╣ ╟╣╣ ╬╬╬╬┐ ╙╬╬╣╣ ╫╣╣╣╬ ╟╣╣╬ ╟╣╣╣ ╟╣╣╬ ╣╣╣ ╣╣╣ ╟╣╣ ╣╣╣┌╣╣╜ ╬╬╬╜ ╬╬╣╣ ╙╝╣╣╬ ╙╣╣╣╗╖╓╗╣╣╣╜ ╟╣╣╬ ╣╣╣ ╣╣╣ ╟╣╣╦╓ ╣╣╣╣╣ ╙ ╓╦╖ ╬╬╣╣ ╓╗╗╖ ╙╝╣╣╣╣╝╜ ╘╝╝╜ ╝╝╝ ╝╝╝ ╙╣╣╣ ╟╣╣╣ ╩╬╬╬╬╬╬╦╦╬╬╣╣╗╣╣╣╣╣╣╣╝ ╫╣╣╣╣ ╙╬╬╬╬╬╬╬╣╣╣╣╣╣╝╜ ╙╬╬╬╣╣╣╜ ╙

Version information: ml-agents: 1.0.0, ml-agents-envs: 1.0.0, Communicator API: 1.5.0, PyTorch: 2.1.1+cpu D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\torch__init.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ..\torch\csrc\tensor\python_tensor.cpp:453.) _C._set_default_tensor_type(t) [INFO] Listening on port 5004. Start training by pressing the Play button in the Unity Editor. [INFO] Connected to Unity environment with package version 3.0.0-exp.1 and communication version 1.5.0 [INFO] Connected new brain: 3DBall?team=0 [WARNING] Deleting TensorBoard data events.out.tfevents.1702495905.Lokiare.42372.0 that was left over from a previous run. [INFO] Hyperparameters for behavior name 3DBall: trainer_type: ppo hyperparameters: batch_size: 64 buffer_size: 12000 learning_rate: 0.0003 beta: 0.001 epsilon: 0.2 lambd: 0.99 num_epoch: 3 shared_critic: False learning_rate_schedule: linear beta_schedule: linear epsilon_schedule: linear checkpoint_interval: 500000 network_settings: normalize: True hidden_units: 128 num_layers: 2 vis_encode_type: simple memory: None goal_conditioning_type: hyper deterministic: False reward_signals: extrinsic: gamma: 0.99 strength: 1.0 network_settings: normalize: False hidden_units: 128 num_layers: 2 vis_encode_type: simple memory: None goal_conditioning_type: hyper deterministic: False init_path: None keep_checkpoints: 5 even_checkpoints: False max_steps: 500000 time_horizon: 1000 summary_freq: 12000 threaded: False self_play: None behavioral_cloning: None [INFO] 3DBall. Step: 12000. Time Elapsed: 16.267 s. Mean Reward: 1.127. Std of Reward: 0.751. Training. [WARNING] Restarting worker[0] after 'The Unity environment took too long to respond. Make sure that : The environment does not need user interaction to launch The Agents' Behavior Parameters > Behavior Type is set to "Default" The environment and the Python interface have compatible versions. If you're running on a headless server without graphics support, turn off display by either passing --no-graphics option or build your Unity executable as server build.' D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\torch__init__.py:614: UserWarning: torch.set_default_tensor_type() is deprecated as of PyTorch 2.1, please use torch.set_default_dtype() and torch.set_default_device() as alternatives. (Triggered internally at ..\torch\csrc\tensor\python_tensor.cpp:453.) _C._set_default_tensor_type(t) [INFO] Listening on port 5004. Start training by pressing the Play button in the Unity Editor. [ERROR] UnityEnvironment worker 0: environment raised an unexpected exception. Traceback (most recent call last): File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 163, in worker env = env_factory(worker_id, side_channels) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\learn.py", line 189, in create_unity_environment return UnityEnvironment( File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents_envs\environment.py", line 242, in init__ if not UnityEnvironment._check_communication_compatibility( File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents_envs\environment.py", line 96, in _check_communication_compatibility if unity_communicator_version.version[0] == 0: AttributeError: 'StrictVersion' object has no attribute 'version' [INFO] Exported results\first3DBallRun\3DBall\3DBall-12102.onnx [INFO] Copied results\first3DBallRun\3DBall\3DBall-12102.onnx to results\first3DBallRun\3DBall.onnx. Traceback (most recent call last): File "D:\Users\lokia\anaconda3\envs\mlagents\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "D:\Users\lokia\anaconda3\envs\mlagents\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\Users\lokia\anaconda3\envs\mlagents\Scripts\mlagents-learn.exe__main__.py", line 7, in File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\learn.py", line 267, in main run_cli(parse_command_line()) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\learn.py", line 263, in run_cli run_training(run_seed, options, num_areas) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\learn.py", line 137, in run_training tc.start_learning(env_manager) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents_envs\timers.py", line 305, in wrapped return func(*args, *kwargs) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\trainer_controller.py", line 175, in start_learning n_steps = self.advance(env_manager) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents_envs\timers.py", line 305, in wrapped return func(args, **kwargs) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\trainer_controller.py", line 233, in advance new_step_infos = env_manager.get_steps() File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\env_manager.py", line 124, in get_steps new_step_infos = self._step() File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 420, in _step self._restart_failed_workers(step) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 328, in _restart_failed_workers self.reset(self.env_parameters) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\env_manager.py", line 68, in reset self.first_step_infos = self._reset_env(config) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 446, in _reset_env ew.previous_step = EnvironmentStep(ew.recv().payload, ew.worker_id, {}, {}) File "D:\Users\lokia\anaconda3\envs\mlagents\lib\site-packages\mlagents\trainers\subprocess_env_manager.py", line 101, in recv raise env_exception AttributeError: 'StrictVersion' object has no attribute 'version'

github-actions[bot] commented 8 months ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 7 months ago

This issue was closed because it has been inactive for 14 days since being marked as stale. Please open a new issue for related bugs.

An-u-rag commented 7 months ago

I am still facing this issue. Upon further checking, it seems like it is only fixed for the develop branch but not yet pushed to the latest release branch. "release-21" still suffers with this issue and imports Barracuda in "com.unity.ml-agents\Runtime\Policies\BehaviorParameters.cs" in the first line of the code.

An-u-rag commented 7 months ago

For reference this is my process to install ML-Agents:

  1. clone the ML-Agents repository --branch release_21
  2. Go to Unity project, Package Manager -> Unity Registry -> Search for "ML Agents"
  3. The only search result I get is 2.0.1 version which seems pretty outdated? So I don't install it.
  4. Then I click the "+" sign and add from disk, then I select the package.json in "com.unity.ml-agents".
  5. I immediately get the above stated errors - even before explicitly importing the 3DBall scene.

C:\ml-agents\com.unity.ml-agents\Runtime\Policies\BehaviorParameters.cs(1,13): error CS0234: The type or namespace name 'Barracuda' does not exist in the namespace 'Unity' (are you missing an assembly reference?)

C:\ml-agents\com.unity.ml-agents\Runtime\Policies\BehaviorParameters.cs(105,16): error CS0246: The type or namespace name 'NNModel' could not be found (are you missing a using directive or an assembly reference?)

C:\ml-agents\com.unity.ml-agents\Runtime\Policies\BehaviorParameters.cs(98,9): error CS0246: The type or namespace name 'NNModel' could not be found (are you missing a using directive or an assembly reference?)

Kr1shu01 commented 5 months ago

D:\Unity\packages\ml-agents-release_21\com.unity.ml-agents\Runtime\Policies\BehaviorParameters.cs(1,13): error CS0234: The type or namespace name 'Barracuda' does not exist in the namespace 'Unity' (are you missing an assembly reference?) THAT IS ALL ...SO HOW?

RishiMalhotra920 commented 4 months ago

Here's what I did: I clicked the console tab on Unity and checked for all compliation issues. Then I went to the branch the maintainer above noted: https://github.com/Unity-Technologies/ml-agents/pull/6030. I opened the files that were throwing errors in VSCode. I found the same files in the pull request. I replaced the local versions of my files with the ones on the pull request.

It seems like the tutorial asks you to clone a stale branch version with outdated assets.

RishiMalhotra920 commented 4 months ago

For example, I saw that dragging and dropping Assets/ML-Agents/Examples/3DBall/TFModels/3DBall.nn into the agent's model field didn't work. I had to download 3dBall, 3dBallHard, Visual3DBall etc. into Assets/ML-Agents/Examples/3DBall/TFModels and fix that.

XRFstudent commented 4 months ago

Here's what I did: I clicked the console tab on Unity and checked for all compliation issues. Then I went to the branch the maintainer above noted: #6030. I opened the files that were throwing errors in VSCode. I found the same files in the pull request. I replaced the local versions of my files with the ones on the pull request.

It seems like the tutorial asks you to clone a stale branch version with outdated assets.

Thank you for your solution @RishiMalhotra920 it worked for me. To complement with further details I followed his solution quoted above and replaced the following files exactly:

forbiddenname commented 3 months ago

Here's what I did: I clicked the console tab on Unity and checked for all compliation issues. Then I went to the branch the maintainer above noted: #6030. I opened the files that were throwing errors in VSCode. I found the same files in the pull request. I replaced the local versions of my files with the ones on the pull request. It seems like the tutorial asks you to clone a stale branch version with outdated assets.

Thank you for your solution @RishiMalhotra920 it worked for me. To complement with further details I followed his solution quoted above and replaced the following files exactly:

* com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  from https://github.com/Unity-Technologies/ml-agents/blob/develop/com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs

* Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
  from https://github.com/Unity-Technologies/ml-agents/blob/develop/Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs

Thank you, I have solved my problem