Offline BC learning
Hello, I am trying to do BC learning using observations and actions collected from several sessions of game play. Currently I am hacking the standard BC learning setup, by having a teacher with a heuristic brain and reading and passing the observations and actions from the offline data set. However I don't believe this to be an efficient approach as I am limiting the training to one sample per frame. So wondering if there is a more efficient way? For example can I setup training session using only the server side python library without having a unity client?
@awjuliani
Hi @hyounesy,
We are actually going to be providing an offline behavioral cloning solution in ML-Agents v0.6. You can actually test it out here: https://github.com/Unity-Technologies/ml-agents/tree/release-v0.6.
That's awesome. Thanks @awjuliani. So looking at the code, I see that DemonstrationStore is responsible for creating the demo files. Is it safe to assume that I can utilize same functionality in a none-editor build to create demo files. Asking because my training data is collected from the game running on a device.
It is currently designed to only work in Editor mode, since the intention is to collect demonstration from the developer directly. It should be possible to remove this check from the code itself however.
Thanks. Makes sense. FYI, we do in fact collect demo data from developers, but it done from device builds. I'd certainly prefer to give this a try before investing further on my current hacky solution. Checking the 0.6 documentation, looks like I need to update to a newer TensorFlowSharp package, but I cannot find it. I understand it is work in progress, but is there an ETA on when that will be made available? Thanks again.
HI @hyounesy,
We don't have an exact date yet for v0.6, but it should be available in the next few weeks.
I'm trying to get this working and keep receiving the following error message in Anaconda.
File "c:\users********\anaconda3\lib\site-packages\mlagents-0.5.0-py3.6.egg\mlagents\trainers\demo_loader.py", line 85, in load_demonstration agent_info.ParseFromString(data[pos:pos + next_pos]) google.protobuf.message.DecodeError: Error parsing message
Hi @BartMartner
Can you give a little more information about the branch you are using, as well as the environment you tried and the OS you are on?
Sure! I'm on Windows and the release-0.6 branch. I'm using Anaconda.
I've just uninstalled and reinstalled protobuf and tensorflow, and now I'm getting a different error. Maybe that's progress?
Now I'm getting: WARNING:mlagents.envs: No External Brains found in the Unity Environment. You will not be able to pass actions to your agent(s).
My scene has an academy and agent with a learning brain linked in. I'm not sure what the issue is.
Just a heads up. It seems to work with the latest release.
@BartMartner That is great to hear. We made a point of testing it on Windows before release, and didn't run into any issues ourselves.
Could you save me? I'm a novice. I'm working on a game. The basic idea is to collect data from users and then train AI with data. My idea is to collect data by providing DemonstrationRecorder, then upload it to the server, and finally feed them to the BC offline algorithm. Is this method feasible? Could you give me some advice?
Could you save me? I'm a novice. I'm working on a game. The basic idea is to collect data from users and then train AI with data. My idea is to collect data by providing DemonstrationRecorder, then upload it to the server, and finally feed it to the BC offline algorithm. Is this method feasible? Could you give me some advice?
As far as I know with the current version, you can only record demonstrations in the editor and playback a single one for training. I had a similar requirement, and I ended up creating a custom one myself. It was not very difficult actually, here is the overall setup:
I created a MyAgentRecorder class to record and playback the array of observations+actions. Then,
For collecting training data:
- Player agent has a heuristic brain, with a MyRecordedDecision subclass that overrides the Decide() to take the current action performed by the player from input controller (keyboard, touch, etc) and pass to the MyAgentRecorder
- Get the current Observations in the PlayerAgent.CollectObservations() and pass them to MyAgentRecorder
- Created a python POST server and use UnityWebRequest.Post to upload the serialized array of observations as demo files.
For training:
- MyAgentRecorder takes the directory of all demo files, loads them one by one (looped in a random sequence) and plays through them frame by frame.
- Setup a classic BC training, with the teacher agent having a heuristic brain that takes the current frames action from the MyAgentRecorder.
- TeacherAgent.CollectObservations() takes the current frame's stored observation from the MyAgentRecorder
Hi @hyounesy, the functionality you've implemented here, especially the ability to save, load, and play back a whole directory of .demo files, could be useful to a lot of people who use ml-agents.
Would you be interested in turning it into a feature for ml-agents?
Hi @ervteng , I would have loved to, but unfortunately that is difficult as the code has dependencies to our work in progress game.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.