Downloads · 30 days
8
8% of all-time downloads
cajcodes/dqn-floorplan-navigator
dqn-floorplan-navigator is a reinforcement learning model from cajcodes. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
This model is a Deep Q-Network (DQN) designed to find the most efficient path through a floorplan without hitting obstacles. The model combines traditional pathfinding algorithms with reinforcement learning for optima…
Downloads · 30 days
8
8% of all-time downloads
All-time downloads
100
Public
Repo size
797 KB
Likes
1
Public
Click a slice to open those files.
.tar658 KB · 91%
From the Hugging Face model README
This model is a Deep Q-Network (DQN) designed to find the most efficient path through a floorplan without hitting obstacles. The model combines traditional pathfinding algorithms with reinforcement learning for optimal performance.
The model is a fully connected neural network with the following architecture:
The model was trained using a hybrid approach:
Checkpoints are saved during training for convenience:
checkpoint_11.pth.tar: After 11 episodescheckpoint_21.pth.tar: After 21 episodescheckpoint_31.pth.tar: After 31 episodescheckpoint_41.pth.tar: After 41 episodesTo use this model, load the saved state dictionary and initialize the DQN with the same architecture. The model can then be used to navigate a floorplan and find the most efficient path to the target.
import torch
# Define the DQN class (same as in the training script)
class DQN(nn.Module):
def __init__(self, input_size, hidden_sizes, output_size):
super(DQN, self).__init__()
self.input_size = input_size
self.hidden_sizes = hidden_sizes
self.output_size = output_size
self.fc_layers = nn.ModuleList()
prev_size = input_size
for size in hidden_sizes:
self.fc_layers.append(nn.Linear(prev_size, size))
prev_size = size
self.output_layer = nn.Linear(prev_size, output_size)
def forward(self, x):
if len(x.shape) > 2:
x = x.view(x.size(0), -1)
for layer in self.fc_layers:
x = F.relu(layer(x))
x = self.output_layer(x)
return x
# Load the model
input_size = 100 # 10x10 grid flattened
hidden_sizes = [64, 64]
output_size = 4
model = DQN(input_size, hidden_sizes, output_size)
model.load_state_dict(torch.load('dqn_model.pth'))
model.eval()
# Use the model for inference (example state)
state = ... # Define your state here
with torch.no_grad():
action = model(torch.tensor(state, dtype=torch.float32).unsqueeze(0)).argmax().item()
The training script train.py is included in the repository for those who wish to reproduce the training process or continue training from a specific checkpoint.
bash
Copy code
python train.py
To continue training from a checkpoint, modify the script to load the checkpoint before training.
The model was evaluated based on:
This project leverages the power of reinforcement learning combined with traditional pathfinding algorithms to navigate complex environments efficiently.
This model is licensed under the Apache 2.0 License.
If you use this model in your research, please cite it as follows:
@misc{jones2024dqnfloorplan,
author = {Christopher Jones},
title = {Deep Q-Network for Floorplan Navigation},
year = {2024},
howpublished = {\url{https://huggingface.co/cajcodes/dqn-floorplan-navigator}},
note = {Accessed: YYYY-MM-DD}
}