Skip to content

Commit

Permalink
Small fixes and updates for the python 3.11 upgrade (#1172)
Browse files Browse the repository at this point in the history
* Removed deprecated padding in ui 
* Used modern form of package versioning in setup.
* Fix telemetry test after paho upgrade
* Fix tensorrt interpreter for tf 2.15, which now returns a list instead of a dictionary.
* Peg pytorch to version 2.1 to avoid incompatibilities with nvidia libraries 
* Fix warnings caused by using legacy warn() method instead of warning().
* Switch of fastai trying to use cuda as this crashes if an Nvidia GPU is found. 
* Bump version
  • Loading branch information
DocGarbanzo authored Apr 1, 2024
1 parent 0b39ebe commit 6dade16
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 33 deletions.
2 changes: 1 addition & 1 deletion donkeycar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pyfiglet import Figlet
import logging

__version__ = '5.1.dev1'
__version__ = '5.1.dev2'

logging.basicConfig(level=os.environ.get('LOGLEVEL', 'INFO').upper())

Expand Down
2 changes: 1 addition & 1 deletion donkeycar/management/kivy_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def read_file(self):
Logger.info(f'Donkeyrc: Donkey file {self.file_path} loaded.')
return data
else:
Logger.warn(f'Donkeyrc: Donkey file {self.file_path} does not '
Logger.warning(f'Donkeyrc: Donkey file {self.file_path} does not '
f'exist.')
return {}

Expand Down
18 changes: 9 additions & 9 deletions donkeycar/parts/actuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
try:
import RPi.GPIO as GPIO
except ImportError as e:
logger.warn(f"RPi.GPIO was not imported. {e}")
logger.warning(f"RPi.GPIO was not imported. {e}")
globals()["GPIO"] = None

from donkeycar.parts.pins import OutputPin, PwmPin, PinState
Expand Down Expand Up @@ -800,10 +800,10 @@ def run(self, throttle:float) -> None:
where 1 is full forward and -1 is full backwards.
"""
if throttle is None:
logger.warn("TwoWheelSteeringThrottle throttle is None")
logger.warning("TwoWheelSteeringThrottle throttle is None")
return
if throttle > 1 or throttle < -1:
logger.warn( f"TwoWheelSteeringThrottle throttle is {throttle}, but it must be between 1(forward) and -1(reverse)")
logger.warning( f"TwoWheelSteeringThrottle throttle is {throttle}, but it must be between 1(forward) and -1(reverse)")
throttle = clamp(throttle, -1, 1)

self.speed = throttle
Expand Down Expand Up @@ -843,16 +843,16 @@ def run(self, throttle:float, steering:float) -> Tuple[float, float]:
where 1 is full forward and -1 is full backwards.
"""
if throttle is None:
logger.warn("TwoWheelSteeringThrottle throttle is None")
logger.warning("TwoWheelSteeringThrottle throttle is None")
return
if steering is None:
logger.warn("TwoWheelSteeringThrottle steering is None")
logger.warning("TwoWheelSteeringThrottle steering is None")
return
if throttle > 1 or throttle < -1:
logger.warn( f"TwoWheelSteeringThrottle throttle is {throttle}, but it must be between 1(forward) and -1(reverse)")
logger.warning( f"TwoWheelSteeringThrottle throttle is {throttle}, but it must be between 1(forward) and -1(reverse)")
throttle = clamp(throttle, -1, 1)
if steering > 1 or steering < -1:
logger.warn( f"TwoWheelSteeringThrottle steering is {steering}, but it must be between 1(right) and -1(left)")
logger.warning( f"TwoWheelSteeringThrottle steering is {steering}, but it must be between 1(right) and -1(left)")
steering = clamp(steering, -1, 1)

left_motor_speed = throttle
Expand Down Expand Up @@ -920,10 +920,10 @@ def run(self, throttle:float) -> None:
where 1 is full forward and -1 is full backwards.
"""
if throttle is None:
logger.warn("TwoWheelSteeringThrottle throttle is None")
logger.warning("TwoWheelSteeringThrottle throttle is None")
return
if throttle > 1 or throttle < -1:
logger.warn( f"TwoWheelSteeringThrottle throttle is {throttle}, but it must be between 1(forward) and -1(reverse)")
logger.warning( f"TwoWheelSteeringThrottle throttle is {throttle}, but it must be between 1(forward) and -1(reverse)")
throttle = clamp(throttle, -1, 1)

self.speed = throttle
Expand Down
6 changes: 3 additions & 3 deletions donkeycar/parts/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def init(self):
except ModuleNotFoundError:
self.num_axes = 0
self.num_buttons = 0
logger.warn("no support for fnctl module. joystick not enabled.")
logger.warning("no support for fnctl module. joystick not enabled.")
return False

if not os.path.exists(self.dev_fn):
logger.warn(f"{self.dev_fn} is missing")
logger.warning(f"{self.dev_fn} is missing")
return False

'''
Expand Down Expand Up @@ -965,7 +965,7 @@ def emergency_stop(self):
'''
initiate a series of steps to try to stop the vehicle as quickly as possible
'''
logger.warn('E-Stop!!!')
logger.warning('E-Stop!!!')
self.mode = "user"
self.recording = False
self.constant_throttle = False
Expand Down
7 changes: 3 additions & 4 deletions donkeycar/parts/fastai.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,10 @@ def train(self,
model = self.interpreter.model

dataLoader = DataLoaders.from_dsets(train_data, validation_data, bs=batch_size, shuffle=False)
if torch.cuda.is_available():
dataLoader.cuda()
# old way of enabling gpu now crashes with torch 2.1.*
# if torch.cuda.is_available():
# dataLoader.cuda()

#dataLoaderTest = self.dataBlock.dataloaders.test_dl(validation_data, with_labels=True)
#print(dataLoader.train[0])

callbacks = [
EarlyStoppingCallback(monitor='valid_loss',
Expand Down
6 changes: 3 additions & 3 deletions donkeycar/parts/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,12 @@ def load(self, model_path: str) -> None:
def predict_from_dict(self, input_dict):
for k, v in input_dict.items():
input_dict[k] = self.expand_and_convert(v)
out_dict = self.graph_func(**input_dict)
out_list = self.graph_func(**input_dict)
# Squeeze here because we send a batch of size one, so pick first
# element. To return the order of outputs as defined in the model we
# need to iterate through the model's output shapes here
outputs = [out_dict[k].numpy().squeeze(axis=0) for k in
self.output_keys]
outputs = [k.numpy().squeeze(axis=0) for k in out_list]

# don't return list if output is 1d
return outputs if len(outputs) > 1 else outputs[0]

Expand Down
6 changes: 3 additions & 3 deletions donkeycar/parts/kinematics.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def run(self, steering) -> float:
return 0

if steering > 1 or steering < -1:
logger.warn(f"steering = {steering}, but must be between 1(right) and -1(left)")
logger.warning(f"steering = {steering}, but must be between 1(right) and -1(left)")

steering = clamp(steering, -1, 1)

Expand Down Expand Up @@ -632,14 +632,14 @@ def differential_steering(throttle: float, steering: float, steering_zero: float
logger.error("throttle must be a number")
return 0, 0
if throttle > 1 or throttle < -1:
logger.warn(f"throttle = {throttle}, but must be between 1(right) and -1(left)")
logger.warning(f"throttle = {throttle}, but must be between 1(right) and -1(left)")
throttle = clamp(throttle, -1, 1)

if not is_number_type(steering):
logger.error("steering must be a number")
return 0, 0
if steering > 1 or steering < -1:
logger.warn(f"steering = {steering}, but must be between 1(right) and -1(left)")
logger.warning(f"steering = {steering}, but must be between 1(right) and -1(left)")
steering = clamp(steering, -1, 1)

left_throttle = throttle
Expand Down
4 changes: 2 additions & 2 deletions donkeycar/parts/pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ def pwm_pin(
gpio_pin_pull = [None, GPIO.PUD_OFF, GPIO.PUD_DOWN, GPIO.PUD_UP]
gpio_pin_scheme = {PinScheme.BOARD: GPIO.BOARD, PinScheme.BCM: GPIO.BCM}
except ImportError:
logger.warn("RPi.GPIO was not imported.")
logger.warning("RPi.GPIO was not imported.")
globals()["GPIO"] = None


Expand Down Expand Up @@ -753,7 +753,7 @@ def duty_cycle(self, duty: float) -> None:
pigpio_pin_edge = [None, pigpio.RISING_EDGE, pigpio.FALLING_EDGE, pigpio.EITHER_EDGE]
pigpio_pin_pull = [None, pigpio.PUD_OFF, pigpio.PUD_DOWN, pigpio.PUD_UP]
except ImportError:
logger.warn("pigpio was not imported.")
logger.warning("pigpio was not imported.")
globals()["pigpio"] = None


Expand Down
8 changes: 4 additions & 4 deletions donkeycar/parts/serial_port.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def readBytes(self, count:int=0) -> Tuple[bool, bytes]:
input = self.ser.read(count)
return (waiting, input)
except (serial.serialutil.SerialException, TypeError):
logger.warn("failed reading bytes from serial port")
logger.warning("failed reading bytes from serial port")
return (False, b'')

def read(self, count:int=0) -> Tuple[bool, str]:
Expand Down Expand Up @@ -135,11 +135,11 @@ def readln(self) -> Tuple[bool, str]:
input = buffer.decode(self.charset)
return (waiting, input)
except (serial.serialutil.SerialException, TypeError):
logger.warn("failed reading line from serial port")
logger.warning("failed reading line from serial port")
return (False, "")
except UnicodeDecodeError:
# the first read often includes mis-framed garbase
logger.warn("failed decoding unicode line from serial port")
logger.warning("failed decoding unicode line from serial port")
return (False, "")

def writeBytes(self, value:bytes):
Expand All @@ -150,7 +150,7 @@ def writeBytes(self, value:bytes):
try:
self.ser.write(value)
except (serial.serialutil.SerialException, TypeError):
logger.warn("Can't write to serial port")
logger.warning("Can't write to serial port")

def write(self, value:str):
"""
Expand Down
2 changes: 1 addition & 1 deletion donkeycar/parts/tachometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def __init__(self, gpio_pin: InputPin, debounce_ns:int=0, debug=False):
self.debounce_ns:int = debounce_ns
self.debounce_time:int = 0
if self.debounce_ns > 0:
logger.warn("GpioEncoder debounce_ns will be ignored.")
logger.warning("GpioEncoder debounce_ns will be ignored.")
self.lock = threading.Lock()

def _cb(self):
Expand Down
2 changes: 1 addition & 1 deletion donkeycar/tests/test_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_keras_vs_tflite_and_tensorrt(keras_pilot, tmp_dir):
# lstm cells are not yet supported in tensor RT
out3 = k_trt.run(*args)
assert out3 == approx(out1, rel=TOLERANCE, abs=TOLERANCE)
print("\n", out1, out2, out3)
print('keras:', out1, 'tflite:', out2, 'trt:', out3)



Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ dev =
mypy

torch =
torch
torch==2.1.*
pytorch-lightning
torchvision
torchaudio
Expand Down

0 comments on commit 6dade16

Please sign in to comment.