Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
53 changes: 53 additions & 0 deletions nyxNOVA-master/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
![nyxNOVA Logo](nyxNOVA-fe/nyxNova-site/public/images/display.png)

### *"nyxNOVA merges cutting-edge exoplanet cartography with intelligent navigation, paving the way for next-generation cosmic exploration. Our solution harnesses the power of AI to decode the cosmo's enigmatic terrain and chart safe passages for future missions."*

### Features:

- Celestial Sentinel: Our AI-powered cosmic detective scans the exoplanet surface, unveiling hidden craters and boulders with unprecedented precision.
- Cosmic Pathfinder: Crafting safe routes through the cosmo's treacherous regions, our navigation system ensures rovers can traverse the any landscape with confidence.
- Cosmic Laboratory: Strategic pit stops for scientific exploration are seamlessly integrated into our navigation plans, maximizing the scientific yield of each mission.

## Installation

### Prerequisites

- Python 3.8+
- Node.js 14.x or later
- npm

### Backend Setup

1. Clone the repository:
`git clone https://github.com/stardust-crusaders-x/nyxNOVA.git
cd nyxNOVA-be`

3. Set up a virtual environment:
`python -m venv venv
source venv/bin/activate # On Windows use venv\Scripts\activate`
4. Install required packages:
`pip install -r requirements.txt`
or
`pip install pqdict segmentation_models_pytorch`
`pip install pytorch-lightning`
`pip install torch`
### Frontend Setup

1. Navigate to the frontend directory:
`cd nyxNOVA-fe`
`exoplanet charting: cd Exoplanet\Atmos_tut\r3f-wawatmos-starter`
3. Install dependencies:
`npm install` `yarn install`
4. Run the development server:
web ~ ``cd nyxNova-site
npm run dev``
sim ~ ``cd MoonLander-Simulator``
ed ~ ``cd Exoplanet\Atmos_tut\r3f-wawatmos-starter
yarn dev``


Project Link: [https://github.com/stardust-crusaders-x/nyxNOVA](https://github.com/stardust-crusaders-x/nyxNOVA)

*"One small step for a cosmo, one giant leap for space exploration."*
— The nyxNOVA Vanguard

Binary file added nyxNOVA-master/nyxNOVA-be/best.pt
Binary file not shown.
Binary file not shown.
62 changes: 62 additions & 0 deletions nyxNOVA-master/nyxNOVA-be/infer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import matplotlib.pyplot as plt
import torch
from ultralytics import YOLO
import glob
import random
import torchvision.transforms.functional as F
import numpy as np
from neural_astar.planner import NeuralAstar
from neural_astar.utils.training import load_from_ptl_checkpoint

device = "cpu"
model = YOLO('yolov10l.yaml')
model = YOLO("best.pt")

paths = glob.glob('trail\\WhatsApp\\*.jpeg')
ind = random.randint(0, len(paths) - 1)
img_path = paths[ind]

img = plt.imread(img_path)
results = model.predict(img, save=True, imgsz=640, conf=0.5, iou=0.5, save_txt=True, save_conf=True, save_dir='D:\\isro_hack\\predictions')
binary_map = [[1 for _ in range(img.shape[1])] for _ in range(img.shape[0])]

for result in results:
boxes = result.boxes.xyxy
for box in boxes:
x1, y1, x2, y2 = map(int, box)
for i in range(y1, y2):
for j in range(x1, x2):
binary_map[i][j] = 0

dilated_map = F.resize(torch.tensor(binary_map).unsqueeze(0).float(), size=(32, 32)).squeeze(0).numpy().astype(np.uint8)

def is_valid_point(point, dilated_map):
return dilated_map[point[0], point[1]] == 1

while True:
start_point = (random.randint(0, 31), random.randint(0, 31))
if is_valid_point(start_point, dilated_map):
break

while True:
goal_point = (random.randint(0, 31), random.randint(0, 31))
if is_valid_point(goal_point, dilated_map) and goal_point != start_point:
break

start_map = torch.zeros((1, 32, 32), dtype=torch.float32)
start_map[0, start_point[0], start_point[1]] = 1.0

goal_map = torch.zeros((1, 32, 32), dtype=torch.float32)
goal_map[0, goal_point[0], goal_point[1]] = 1.0

dilated_map = torch.tensor(dilated_map).unsqueeze(0).float().to(device)

neural_astar = NeuralAstar(encoder_arch='CNN').to(device)
neural_astar.load_state_dict(load_from_ptl_checkpoint("D:\\isro_hack\\model\\mazes_032_moore_c8\\lightning_logs\\version_0\\checkpoints\\"))

neural_astar.eval()
na_outputs = neural_astar(dilated_map, start_map.to(device), goal_map.to(device), store_intermediate_results=True)

print(torch.unique(na_outputs[-1][-1]['paths']))
plt.imshow(na_outputs[-1][-1]['paths'][0].permute(1, 2, 0).cpu().detach().numpy(), cmap='gray')
plt.show()
Binary file added nyxNOVA-master/nyxNOVA-be/mars.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions nyxNOVA-master/nyxNOVA-be/neural_astar/planner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .astar import NeuralAstar, VanillaAstar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
213 changes: 213 additions & 0 deletions nyxNOVA-master/nyxNOVA-be/neural_astar/planner/astar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
"""Neural A* search
Author: Ryo Yonetani
Affiliation: OSX
"""
from __future__ import annotations

from functools import partial

import torch
import torch.nn as nn

from . import encoder
from .differentiable_astar import AstarOutput, DifferentiableAstar
from .pq_astar import pq_astar


class VanillaAstar(nn.Module):
def __init__(
self,
g_ratio: float = 0.5,
use_differentiable_astar: bool = True,
):
"""
Vanilla A* search

Args:
g_ratio (float, optional): ratio between g(v) + h(v). Set 0 to perform as best-first search. Defaults to 0.5.
use_differentiable_astar (bool, optional): if the differentiable A* is used instead of standard A*. Defaults to True.

Examples:
>>> planner = VanillaAstar()
>>> outputs = planner(map_designs, start_maps, goal_maps)
>>> histories = outputs.histories
>>> paths = outputs.paths

Note:
For perform inference on a large map, set use_differentiable_astar = False to peform a faster A* with priority queue
"""

super().__init__()
self.astar = DifferentiableAstar(
g_ratio=g_ratio,
Tmax=1.0,
)
self.g_ratio = g_ratio
self.use_differentiable_astar = use_differentiable_astar

def perform_astar(
self,
map_designs: torch.tensor,
start_maps: torch.tensor,
goal_maps: torch.tensor,
obstacles_maps: torch.tensor,
store_intermediate_results: bool = False,
) -> AstarOutput:

astar = (
self.astar
if self.use_differentiable_astar
else partial(pq_astar, g_ratio=self.g_ratio)
)

astar_outputs = astar(
map_designs,
start_maps,
goal_maps,
obstacles_maps,
store_intermediate_results,
)

return astar_outputs

def forward(
self,
map_designs: torch.tensor,
start_maps: torch.tensor,
goal_maps: torch.tensor,
store_intermediate_results: bool = False,
) -> AstarOutput:
"""
Perform A* search

Args:
map_designs (torch.tensor): map designs (obstacle maps or raw image)
start_maps (torch.tensor): start maps indicating the start location with one-hot binary map
goal_maps (torch.tensor): goal maps indicating the goal location with one-hot binary map
store_intermediate_results (bool, optional): If the intermediate search results are stored in Astar output. Defaults to False.

Returns:
AstarOutput: search histories and solution paths, and optionally intermediate search results.
"""

cost_maps = map_designs
obstacles_maps = map_designs

return self.perform_astar(
cost_maps,
start_maps,
goal_maps,
obstacles_maps,
store_intermediate_results,
)


class NeuralAstar(VanillaAstar):
def __init__(
self,
g_ratio: float = 0.5,
Tmax: float = 1.0,
encoder_input: str = "m+",
encoder_arch: str = "CNN",
encoder_depth: int = 4,
learn_obstacles: bool = False,
const: float = None,
use_differentiable_astar: bool = True,
):
"""
Neural A* search

Args:
g_ratio (float, optional): ratio between g(v) + h(v). Set 0 to perform as best-first search. Defaults to 0.5.
Tmax (float, optional): how much of the map the model explores during training. Set a small value (0.25) when training the model. Defaults to 1.0.
encoder_input (str, optional): input format. Set "m+" to use the concatenation of map_design and (start_map + goal_map). Set "m" to use map_design only. Defaults to "m+".
encoder_arch (str, optional): encoder architecture. Defaults to "CNN".
encoder_depth (int, optional): depth of the encoder. Defaults to 4.
learn_obstacles (bool, optional): if the obstacle is invisible to the model. Defaults to False.
const (float, optional): learnable weight to be multiplied for h(v). Defaults to None.
use_differentiable_astar (bool, optional): if the differentiable A* is used instead of standard A*. Defaults to True.

Examples:
>>> planner = NeuralAstar()
>>> outputs = planner(map_designs, start_maps, goal_maps)
>>> histories = outputs.histories
>>> paths = outputs.paths

Note:
For perform inference on a large map, set use_differentiable_astar = False to peform a faster A* with priority queue
"""

super().__init__()
self.astar = DifferentiableAstar(
g_ratio=g_ratio,
Tmax=Tmax,
)
self.encoder_input = encoder_input
encoder_arch = getattr(encoder, encoder_arch)
self.encoder = encoder_arch(len(self.encoder_input), encoder_depth, const)
self.learn_obstacles = learn_obstacles
if self.learn_obstacles:
print("WARNING: learn_obstacles has been set to True")
self.g_ratio = g_ratio
self.use_differentiable_astar = use_differentiable_astar

def encode(
self,
map_designs: torch.tensor,
start_maps: torch.tensor,
goal_maps: torch.tensor,
) -> torch.tensor:
"""
Encode the input problem

Args:
map_designs (torch.tensor): map designs (obstacle maps or raw image)
start_maps (torch.tensor): start maps indicating the start location with one-hot binary map
goal_maps (torch.tensor): goal maps indicating the goal location with one-hot binary map

Returns:
torch.tensor: predicted cost maps
"""
inputs = map_designs
if "+" in self.encoder_input:
if map_designs.shape[-1] == start_maps.shape[-1]:
inputs = torch.cat((inputs, start_maps + goal_maps), dim=1)
else:
upsampler = nn.UpsamplingNearest2d(map_designs.shape[-2:])
inputs = torch.cat((inputs, upsampler(start_maps + goal_maps)), dim=1)
cost_maps = self.encoder(inputs)

return cost_maps

def forward(
self,
map_designs: torch.tensor,
start_maps: torch.tensor,
goal_maps: torch.tensor,
store_intermediate_results: bool = False,
) -> AstarOutput:
"""
Perform neural A* search

Args:
map_designs (torch.tensor): map designs (obstacle maps or raw image)
start_maps (torch.tensor): start maps indicating the start location with one-hot binary map
goal_maps (torch.tensor): goal maps indicating the goal location with one-hot binary map
store_intermediate_results (bool, optional): If the intermediate search results are stored in Astar output. Defaults to False.

Returns:
AstarOutput: search histories and solution paths, and optionally intermediate search results.
"""

cost_maps = self.encode(map_designs, start_maps, goal_maps)
obstacles_maps = (
map_designs if not self.learn_obstacles else torch.ones_like(start_maps)
)

return self.perform_astar(
cost_maps,
start_maps,
goal_maps,
obstacles_maps,
store_intermediate_results,
)
Loading