-
Notifications
You must be signed in to change notification settings - Fork 0
One try again #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ExoRoy
wants to merge
10
commits into
main
Choose a base branch
from
one_try_again
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
One try again #41
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9016285
Try d'implementer launch_one_simu dans le refactoring
ExoRoy a8a4cb1
Try d'implementer launch_one_simu dans le refactoring 2
ExoRoy 2c7e8ef
merge avec main
ExoRoy be2e078
Fix : lanch_one_simu.py marche a un peu. Mais Crash au bout de 3 co…
ExoRoy c93157c
Fix : lanch_one_simu.py marche a 100% je crois
ExoRoy 78880f1
Merge branch 'no-data-poisoning' into one_try_again
MatthiasBienvenu 919f057
fix: some refactoring and less magic numbers
MatthiasBienvenu 808f2e5
fix: forgot the .__name__
MatthiasBienvenu 3c9e424
fix: removed B_DEBUG
MatthiasBienvenu c62990d
Merge branch 'main' into one_try_again
MatthiasBienvenu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| import numpy as np | ||
| import onnxruntime as ort | ||
|
|
||
| import simulation.config as c | ||
| from extractors import ( # noqa: F401 | ||
| CNN1DResNetExtractor, | ||
| TemporalResNetExtractor, | ||
| ) | ||
| from simulation import VehicleEnv | ||
| from utils import run_onnx_model | ||
|
|
||
| ONNX_MODEL_PATH = c.save_dir / f"model_{c.ExtractorClass.__name__}.onnx" | ||
|
|
||
|
|
||
| def init_onnx_runtime_session(onnx_path: Path) -> ort.InferenceSession: | ||
| if not os.path.exists(onnx_path): | ||
| raise FileNotFoundError( | ||
| f"The ONNX file could not be found at: {onnx_path}. Please export it first." | ||
| ) | ||
| return ort.InferenceSession(onnx_path) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| if not os.path.exists("/tmp/autotech/"): | ||
| os.mkdir("/tmp/autotech/") | ||
|
|
||
| os.system('if [ -n "$(ls /tmp/autotech)" ]; then rm /tmp/autotech/*; fi') | ||
|
|
||
| # Starting the ONNX session | ||
| try: | ||
| ort_session = init_onnx_runtime_session(ONNX_MODEL_PATH) | ||
| input_name = ort_session.get_inputs()[0].name | ||
| output_name = ort_session.get_outputs()[0].name | ||
| print(f"ONNX model loaded from {ONNX_MODEL_PATH}") | ||
| print(f"Input Name: {input_name}, Output Name: {output_name}") | ||
| except FileNotFoundError as e: | ||
| print(f"ERROR: {e}") | ||
| sys.exit(1) | ||
|
|
||
| env = VehicleEnv(0, 0) | ||
| obs, _ = env.reset() | ||
|
|
||
| print("Starting simulation in inference mode...") | ||
|
|
||
| step_count = 0 | ||
|
|
||
| while True: | ||
| raw_action = run_onnx_model(ort_session, obs[None]) | ||
| logits = np.array(raw_action).flatten() | ||
|
|
||
| steer_logits = logits[: c.n_actions_steering] | ||
| speed_logits = logits[c.n_actions_steering :] | ||
|
|
||
| action_steer = np.argmax(steer_logits) | ||
| action_speed = np.argmax(speed_logits) | ||
|
|
||
| action = np.array([action_steer, action_speed], dtype=np.int64) | ||
|
|
||
| next_obs, reward, done, truncated, info = env.step(action) | ||
|
|
||
| step_count += 1 | ||
|
|
||
| if done: | ||
| print(f"Episode(s) finished after {step_count} steps.") | ||
| step_count = 0 | ||
|
|
||
| fresh_frame = next_obs[:, -1:] | ||
| obs, _ = env.reset() | ||
| env.context[:, -1:] = fresh_frame | ||
| obs = env.context | ||
| else: | ||
| obs = next_obs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| from .plot_model_io import PlotModelIO | ||
| import onnxruntime as ort | ||
| import numpy as np | ||
|
|
||
| __all__ = ["PlotModelIO"] | ||
|
|
||
| def run_onnx_model(session: ort.InferenceSession, x: np.ndarray): | ||
| return session.run(None, {"input": x})[0] | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?