forked from autorope/donkeycar
-
Notifications
You must be signed in to change notification settings - Fork 4
Update upstream #2
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
mgagvani
wants to merge
18
commits into
mgagvani:dev
Choose a base branch
from
autorope:main
base: dev
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
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
60d3241
Update to new albumentations (#1209)
DocGarbanzo eb9c0c8
Change Use_Joystick default to True (#1208)
zlite 6b5aa63
Fix usage of Mock instances
DocGarbanzo d57a1e8
Refactor MQTT telemetry test to improve connection handling and messa…
DocGarbanzo 54d249a
Add Luxonis OAK-D Part (#1204)
mgagvani 225a114
Web based track editor (#1206)
zlite c1e0d8a
Fix MQTT telemetry test reliability by replacing network dependency w…
DocGarbanzo 7cb2b8c
Update packages: unfreeze matplotlib and add tensorflow-metal to maco…
DocGarbanzo 8929c11
Fix WebSocket test race conditions with async polling
DocGarbanzo 7c2a625
Merge branch 'main' of https://github.com/autorope/donkeycar
DocGarbanzo ef51b05
Resize on different default height (#1212)
emmanuel-ferdman 5a89a82
Disable camera alignment for Pi5 compatibility (#1221)
zlite 7419649
Simplified TFLite support (#1222)
zlite ce9ac35
Bump version to 5.2.dev6
DocGarbanzo ddf95e6
Fixed a bug in the TFLite PR (#1224)
zlite 4aacbaf
Typo in README.md (#1225)
zlite 9d34462
Reorganized and cleaned up config file (#1220)
zlite cde8bbe
Create a default for PATH_SEARCH_LENGTH (#1228)
Ezward 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 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
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 |
|---|---|---|
|
|
@@ -4,14 +4,38 @@ | |
| import numpy as np | ||
| from typing import Union, Sequence, List | ||
|
|
||
| import tensorflow as tf | ||
| from tensorflow import keras | ||
| from tensorflow.python.saved_model import tag_constants, signature_constants | ||
| from tensorflow.python.compiler.tensorrt import trt_convert as trt | ||
| try: | ||
| import tensorflow as tf | ||
| from tensorflow import keras | ||
| from tensorflow.python.saved_model import tag_constants, signature_constants | ||
| from tensorflow.python.compiler.tensorrt import trt_convert as trt | ||
| except ImportError: | ||
| tf = None | ||
| keras = None | ||
| tag_constants = None | ||
| signature_constants = None | ||
| trt = None | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def get_tflite_interpreter(): | ||
| """Get TFLite Interpreter from tflite-runtime or full TensorFlow.""" | ||
| try: | ||
| from tflite_runtime.interpreter import Interpreter | ||
| return Interpreter | ||
| except ImportError: | ||
| pass | ||
| try: | ||
| from ai_edge_litert.interpreter import Interpreter | ||
| return Interpreter | ||
| except ImportError: | ||
| pass | ||
| if tf is not None: | ||
| return tf.lite.Interpreter | ||
| raise ImportError("No TFLite runtime found. Install tflite-runtime or tensorflow.") | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TensorRT support check crashes without TensorFlowMedium Severity When TensorFlow imports fail, Additional Locations (1) |
||
| def has_trt_support(): | ||
| try: | ||
| converter = trt.TrtGraphConverterV2() | ||
|
|
@@ -91,14 +115,14 @@ def set_model(self, pilot: 'KerasPilot') -> None: | |
| """ Some interpreters will need the model""" | ||
| pass | ||
|
|
||
| def set_optimizer(self, optimizer: tf.keras.optimizers.Optimizer) -> None: | ||
| def set_optimizer(self, optimizer) -> None: | ||
| pass | ||
|
|
||
| def compile(self, **kwargs): | ||
| raise NotImplementedError('Requires implementation') | ||
|
|
||
| @abstractmethod | ||
| def get_input_shape(self, input_name) -> tf.TensorShape: | ||
| def get_input_shape(self, input_name): | ||
| pass | ||
|
|
||
| def predict(self, img_arr: np.ndarray, *other_arr: np.ndarray) \ | ||
|
|
@@ -127,7 +151,7 @@ class KerasInterpreter(Interpreter): | |
|
|
||
| def __init__(self): | ||
| super().__init__() | ||
| self.model: tf.keras.Model = None | ||
| self.model = None | ||
|
|
||
| def set_model(self, pilot: 'KerasPilot') -> None: | ||
| self.model = pilot.create_model() | ||
|
|
@@ -146,10 +170,10 @@ def set_model(self, pilot: 'KerasPilot') -> None: | |
| self.shapes = (dict(zip(self.input_keys, input_shape)), | ||
| dict(zip(self.output_keys, output_shape))) | ||
|
|
||
| def set_optimizer(self, optimizer: tf.keras.optimizers.Optimizer) -> None: | ||
| def set_optimizer(self, optimizer) -> None: | ||
| self.model.optimizer = optimizer | ||
|
|
||
| def get_input_shape(self, input_name) -> tf.TensorShape: | ||
| def get_input_shape(self, input_name): | ||
| assert self.model, 'Model not set' | ||
| return self.shapes[0][input_name] | ||
|
|
||
|
|
@@ -174,6 +198,18 @@ def predict_from_dict(self, input_dict): | |
| def load(self, model_path: str) -> None: | ||
| logger.info(f'Loading model {model_path}') | ||
| self.model = keras.models.load_model(model_path, compile=False) | ||
| # Set input_keys and output_keys after loading (same as set_model) | ||
| input_shape = self.model.input_shape | ||
| if type(input_shape) is not list: | ||
| input_shape = [input_shape] | ||
| output_shape = self.model.output_shape | ||
| if type(output_shape) is not list: | ||
| output_shape = [output_shape] | ||
|
|
||
| self.input_keys = self.model.input_names | ||
| self.output_keys = self.model.output_names | ||
| self.shapes = (dict(zip(self.input_keys, input_shape)), | ||
| dict(zip(self.output_keys, output_shape))) | ||
|
|
||
| def load_weights(self, model_path: str, by_name: bool = True) -> \ | ||
| None: | ||
|
|
@@ -263,7 +299,8 @@ def load(self, model_path): | |
| 'TFlitePilot should load only .tflite files' | ||
| logger.info(f'Loading model {model_path}') | ||
| # Load TFLite model and extract input and output keys | ||
| self.interpreter = tf.lite.Interpreter(model_path=model_path) | ||
| Interpreter = get_tflite_interpreter() | ||
| self.interpreter = Interpreter(model_path=model_path) | ||
| self.signatures = self.interpreter.get_signature_list() | ||
| self.runner = self.interpreter.get_signature_runner() | ||
| self.input_keys = self.signatures['serving_default']['inputs'] | ||
|
|
@@ -312,7 +349,7 @@ def set_model(self, pilot: 'KerasPilot') -> None: | |
| # state as the trt model hasn't been loaded yet | ||
| self.pilot = pilot | ||
|
|
||
| def get_input_shape(self, input_name) -> tf.TensorShape: | ||
| def get_input_shape(self, input_name): | ||
| assert self.graph_func, "Requires loadin the tensorrt model first" | ||
| return self.graph_func.structured_input_signature[1][input_name].shape | ||
|
|
||
|
|
||
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
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.
The comment has a spelling error: 'libcamera2' should likely be 'libcamera' (without the '2'). The Picamera2 library uses libcamera (not libcamera2) as its underlying camera system.