AndrejGobeX / TrackMania_AI

Racing game AI
GNU General Public License v3.0
100 stars 11 forks source link

Need help to understanding #19

Open jitendracheripally2003 opened 8 months ago

jitendracheripally2003 commented 8 months ago

Hi, this is not an issue but I need to ask you few things

  1. According to you, what is the minimum hardware specifications for this project?
  2. I want to build a RL agent for TM Nations Forever (because I don't have the Trackmania 2020 paid version for using custom maps). Can I use the map extractor and the map array convertor for getting the track array? Will it work, or do we need to change the code?
  3. I also would like to have some guidance from you to build my project. My ideas are: i. Taking distance between tracks and in front of the car and some basic information like speed, etc. as input to the model. ii. Starting with DQN, I want to implement other algorithms.
AndrejGobeX commented 8 months ago
  1. I would say any decent hardware would run this.
  2. You can build custom maps with free version of tm 2020. If you prefer nations, maybe the c# code will work. Check the GBX.NET repo. However, the angelscript code and the openplanet plugin don't work, so you would need to use donadigos TMInterface (I have no idea how to use it). Keep in mind that all of the tracks should be flat for now, I am working on a more flexible solution.
  3. How do you mean taking distance between tracks?
jitendracheripally2003 commented 8 months ago

Is the C# code enough for the track data extraction? I want to give the model input on the distance between the car and track ends, like how LIDAR sensors work so that model can know the environment. LIDAR sensor information can be extracted using image screenshots, but I want to calculate the distance on the fly while driving. Will this work by extracting track information and calculating the distance while racing? Can I know what inputs and how you are feeding them to you model? Thank you for responding!

AndrejGobeX commented 8 months ago

Well I do the same thing. Check the readme. The c# code gives you two arrays of tuples which indicate the edges.

jitendracheripally2003 commented 8 months ago

Okay thank you. I will refer readme, thank you for your guidance.

jitendracheripally2003 commented 8 months ago

Hey, I'm so sorry to bother you. I don't have much knowledge about C# so I'm unable to run the C# program. I have installed C# extensions, C# SDK, .Net 8 this all for VS Code. Can you please explain how can I run that code. I even installed choco but that's not installing scripts to run this.

AndrejGobeX commented 8 months ago

After .NET, cd to MapExtractor/ and from there run dotnet new console I think. Then restore the Program.cs via git (because dotnet new console is going to overwrite it). Then you install GBX.NET and GBX.NET.LZO while you are inside the MapExtractor. Then run the mini project through dotnet. You supply the map file via command line arg.

jitendracheripally2003 commented 8 months ago

Thank you it worked and it works only on Tracks you have given in the repo. I have tried to give TMNF tracks but its showing some error: Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') at System.Collections.Generic.List`1.get_Item(Int32 index) at MapExtractor.Program.Main(String[] args) Can you some assurance that with some changes it may work in TMNF tracks?

AndrejGobeX commented 8 months ago

GBX.NET should work for TMNF, you just need to figure out which classes are for TMNF blocks. I do not know if it is straightforward to convert my script to work on TMNF. Check the GBX.NET repo and dig a bit on how the blocks work. In the end, the simplest thing to do is to record the location of the car while you are driving on the edges and just use those numbers for the track. I know it may not be the best way, but at least you know it will work and you won't get annoyed with automating the whole process. I am working on a solution for 3d tracks and yeah I am stuck with this semi-manual approach because extracting data from the meshes isn't the best way to go.

jitendracheripally2003 commented 8 months ago

I will try my best to convert it for the TMNF. Your idea of recording data while driving on edges is very good and reliable but it like hard coding. Lets keep it for worst case scenario. I hope you good luck for you work, I may not be that much helpful but you are so helpful for me. Thank you.

jitendracheripally2003 commented 6 months ago

Hi, I have a doubt about one thing, you have implemented PPO, A2C, SAC, TD3 which gives discrete or continuous actions. I wanted to see if this works for DQN, for which the stable baseline3 only supports discrete actions. I want to also know for training are you using GPU or CPU. Thank you in advance!

AndrejGobeX commented 6 months ago

CPU. I have tried CUDA but it is slower. I don't know, but I guess you can use DQN if you make it's discrete outputs fit the limits of the env inputs.

jitendracheripally2003 commented 6 months ago

Hi, I have tried to use DQN, there was a error for Box. I think with some modification to that for taking discrete action it will work. Can you please explain the Observation timeout and Action timeout. I was getting them frequently even with PPO driving and training. How can I fill the delay between the game and model. Thank you for your help.

AndrejGobeX commented 6 months ago

It fills the delay automatically. If you see a timeout it means your inference is slow (maybe an older pc?) You can try tweaking the values im the constructor, but I don't think it is going to help.

jitendracheripally2003 commented 6 months ago

Sorry for the late reply, I don't know what's wrong with my laptop, but I brought is 1 month ago. It has a 4050, i5 13th, so maybe these all heavy for me. But thank you for your explanation.

AndrejGobeX commented 6 months ago

Then this is not the issue... Try using cpu instead of cuda.

jitendracheripally2003 commented 6 months ago

Hi, sorry for the late update, CPU is actually better I have trained DDPG algorithm for 1 map and it shows good results. Thank you for your guidance.

koi0823 commented 5 months ago

Thank you it worked and it works only on Tracks you have given in the repo. I have tried to give TMNF tracks but its showing some error: Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index') at System.Collections.Generic.List`1.get_Item(Int32 index) at MapExtractor.Program.Main(String[] args) Can you some assurance that with some changes it may work in TMNF tracks?

I running with trackmania 2020 not TMNF hi can i ask i am same issue with this and didnt generate the txt file out Screenshot 2024-04-25 173859

can i ask why ya ?

koi0823 commented 5 months ago

Screenshot 2024-04-25 174142

i have move the code to above that what chatgpt told me to do

AndrejGobeX commented 5 months ago

Sorry I do not understand.

BlackPeonyFish commented 3 months ago

Dear author, I encountered this problem when I ran your code. This seems to indicate that the map file (txt file) was not read successfully? (my-env) C:\Windows\System32>python "C:\Users\B1793.conda\envs\my-env\code_try\RL_Driver.py" C:\Users\B1793.conda\envs\my-env\Lib\site-packages\stable_baselines3\common\save_util.py:166: UserWarning: Could not deserialize object clip_range. Consider using custom_objects argument to replace this object. Exception: code() argument 13 must be str, not int warnings.warn( C:\Users\B1793.conda\envs\my-env\Lib\site-packages\stable_baselines3\common\save_util.py:166: UserWarning: Could not deserialize object lr_schedule. Consider using custom_objects argument to replace this object. Exception: code() argument 13 must be str, not int warnings.warn( Wrapping the env with a Monitor wrapper Wrapping the env in a DummyVecEnv. Traceback (most recent call last): File "C:\Users\B1793.conda\envs\my-env\code_try\RLDriver.py", line 36, in obs, = env.reset() ^^^^^^^^^^^ File "C:\Users\B1793.conda\envs\my-env\code_try\TrackmaniaEnv.py", line 325, in reset self.respawn() File "C:\Users\B1793.conda\envs\my-env\code_try\TrackmaniaEnv.py", line 154, in respawn self.refresh_observation() File "C:\Users\B1793.conda\envs\my-env\code_try\TrackmaniaEnv.py", line 172, in refresh_observation view = self.visualizer.lidar(self.location, TrackmaniaEnv.vector_angle(self.direction), show=False) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\B1793.conda\envs\my-env\code_try\TrackVisualizer.py", line 112, in lidar img = rotate_image(img, TrackVisualizer.VIEW_CENTER, math.degrees(θ + math.pi/2)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\B1793.conda\envs\my-env\code_try\TrackVisualizer.py", line 16, in rotate_image result = cv2.warpAffine(image, rot_mat, image.shape[:-1]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\imgwarp.cpp:2723: error: (-215:Assertion failed) src.cols > 0 && src.rows > 0 in function 'cv::warpAffine'

In addition, when I run your MapExtractor.py file to process the map file, the running result is only a picture, and no txt file is generated. What is the reason for this?

AndrejGobeX commented 3 months ago

I've switched to image based AI + 3d maps witch require different approaches (and it's incomplete, I might pick it up in the future). Try the main or old_main branches. I have no idea what these logs mean, never used conda nor D: drive for this. I've been offline lately so appologies for low support.