Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flake8==5.0.4
mypy==0.971
mypy==0.991
pylint==2.14.5
pytest==7.1.2
pytest-watch==4.2.0
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy<1.24
opencv-python==4.6.0.66
Pillow==9.2.0
pyfakewebcam==0.1.0
Expand Down
4 changes: 2 additions & 2 deletions tf_bodypix/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ def get_app(self, args: argparse.Namespace) -> AbstractWebcamFilterApp:
}


def parse_args(argv: List[str] = None) -> argparse.Namespace:
def parse_args(argv: Optional[List[str]] = None) -> argparse.Namespace:
parser = argparse.ArgumentParser(
'TensorFlow BodyPix (TF BodyPix)',
formatter_class=argparse.ArgumentDefaultsHelpFormatter
Expand All @@ -678,7 +678,7 @@ def run(args: argparse.Namespace):
sub_command.run(args)


def main(argv: List[str] = None):
def main(argv: Optional[List[str]] = None):
args = parse_args(argv)
if args.debug:
logging.getLogger().setLevel(logging.DEBUG)
Expand Down
16 changes: 8 additions & 8 deletions tf_bodypix/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def is_all_part_names(part_names: Optional[List[str]]) -> bool:

def get_filtered_part_segmentation(
part_segmentation: np.ndarray,
part_names: List[str] = None
part_names: Optional[List[str]] = None
):
if is_all_part_names(part_names):
return part_segmentation
Expand Down Expand Up @@ -269,8 +269,8 @@ def get_scaled_part_heatmap_scores(self, **kwargs) -> np.ndarray:

def get_scaled_part_segmentation(
self,
mask: np.ndarray = None,
part_names: List[str] = None,
mask: Optional[np.ndarray] = None,
part_names: Optional[List[str]] = None,
outside_mask_value: int = -1,
resize_method: Optional[str] = None
) -> np.ndarray:
Expand Down Expand Up @@ -312,7 +312,7 @@ def get_mask(
def get_part_mask(
self,
mask: np.ndarray,
part_names: List[str] = None,
part_names: Optional[List[str]] = None,
resize_method: Optional[str] = None
) -> np.ndarray:
if is_all_part_names(part_names):
Expand All @@ -331,8 +331,8 @@ def get_part_mask(
def get_colored_part_mask(
self,
mask: np.ndarray,
part_colors: List[T_Color] = None,
part_names: List[str] = None,
part_colors: Optional[List[T_Color]] = None,
part_names: Optional[List[str]] = None,
resize_method: Optional[str] = None
) -> np.ndarray:
part_segmentation = self.get_scaled_part_segmentation(
Expand Down Expand Up @@ -597,8 +597,8 @@ def get_architecture_from_model_path(model_path: str) -> str:

def load_model(
model_path: str,
output_stride: int = None,
architecture_name: str = None,
output_stride: Optional[int] = None,
architecture_name: Optional[str] = None,
**kwargs
):
if not output_stride:
Expand Down
2 changes: 1 addition & 1 deletion tf_bodypix/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_webcam_image_source(webcam_number: int, **kwargs) -> T_ImageSource:
@contextmanager
def get_simple_image_source(
path: str,
image_size: ImageSize = None,
image_size: Optional[ImageSize] = None,
**_
) -> Iterator[Iterable[ImageArray]]:
local_image_path = get_file(path)
Expand Down
4 changes: 3 additions & 1 deletion tf_bodypix/utils/dist.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
def get_requirement_groups(requirement):
def get_requirement_groups(requirement): # pylint: disable=too-many-return-statements
requirement_lower = requirement.lower()
if 'tensorflow' in requirement_lower:
return ['tf']
if 'tfjs' in requirement_lower:
return ['tfjs']
if 'numpy' in requirement_lower:
return ['tfjs']
if 'pillow' in requirement_lower:
return ['image']
if 'opencv' in requirement_lower:
Expand Down
6 changes: 3 additions & 3 deletions tf_bodypix/utils/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def rgb_to_bgr(image: np.ndarray) -> np.ndarray:

def _load_image_using_tf(
local_image_path: str,
image_size: ImageSize = None
image_size: Optional[ImageSize] = None
) -> np.ndarray:
image = tf.keras.preprocessing.image.load_img(
local_image_path
Expand All @@ -242,7 +242,7 @@ def _load_image_using_tf(

def _load_image_using_pillow(
local_image_path: str,
image_size: ImageSize = None
image_size: Optional[ImageSize] = None
) -> np.ndarray:
with PIL.Image.open(local_image_path) as image:
image_array = np.asarray(image)
Expand All @@ -253,7 +253,7 @@ def _load_image_using_pillow(

def load_image(
local_image_path: str,
image_size: ImageSize = None
image_size: Optional[ImageSize] = None
) -> np.ndarray:
if tf is not None:
return _load_image_using_tf(local_image_path, image_size=image_size)
Expand Down
22 changes: 11 additions & 11 deletions tf_bodypix/utils/opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import deque
from contextlib import contextmanager
from time import monotonic, sleep
from typing import Callable, ContextManager, Deque, Iterable, Iterator, Union
from typing import Callable, ContextManager, Deque, Iterable, Iterator, Optional, Union

import cv2
import numpy as np
Expand All @@ -23,7 +23,7 @@
def iter_read_raw_video_images(
video_capture: cv2.VideoCapture,
repeat: bool = False,
is_stopped: Callable[[], bool] = None
is_stopped: Optional[Callable[[], bool]] = None
) -> Iterable[ImageArray]:
while is_stopped is None or not is_stopped():
grabbed, image_array = video_capture.read()
Expand All @@ -41,7 +41,7 @@ def iter_read_raw_video_images(

def iter_resize_video_images(
video_images: Iterable[ImageArray],
image_size: ImageSize = None,
image_size: Optional[ImageSize] = None,
interpolation: int = cv2.INTER_LINEAR
) -> Iterable[ImageArray]:
is_first = True
Expand Down Expand Up @@ -70,7 +70,7 @@ def iter_convert_video_images_to_rgb(

def iter_delay_video_images_to_fps(
video_images: Iterable[ImageArray],
fps: float = None
fps: Optional[float] = None
) -> Iterable[np.ndarray]:
if not fps or fps <= 0:
LOGGER.info('no fps requested, providing images from source (without delay)')
Expand Down Expand Up @@ -120,10 +120,10 @@ def iter_delay_video_images_to_fps(

def iter_read_video_images(
video_capture: cv2.VideoCapture,
image_size: ImageSize = None,
image_size: Optional[ImageSize] = None,
interpolation: int = cv2.INTER_LINEAR,
repeat: bool = True,
fps: float = None
fps: Optional[float] = None
) -> Iterable[np.ndarray]:
video_images: Iterable[np.ndarray]
video_images = iter_read_raw_video_images(video_capture, repeat=repeat)
Expand All @@ -138,11 +138,11 @@ def iter_read_video_images(
@contextmanager
def get_video_image_source( # pylint: disable=too-many-locals
path: Union[str, int],
image_size: ImageSize = None,
image_size: Optional[ImageSize] = None,
download: bool = True,
fps: float = None,
fourcc: str = None,
buffer_size: int = None,
fps: Optional[float] = None,
fourcc: Optional[str] = None,
buffer_size: Optional[int] = None,
**_
) -> Iterator[Iterable[ImageArray]]:
local_path: Union[str, int]
Expand Down Expand Up @@ -190,7 +190,7 @@ def get_video_image_source( # pylint: disable=too-many-locals

def get_webcam_image_source(
path: Union[str, int],
fourcc: str = None,
fourcc: Optional[str] = None,
buffer_size: int = 1,
**kwargs
) -> ContextManager[Iterable[ImageArray]]:
Expand Down
4 changes: 2 additions & 2 deletions tf_bodypix/utils/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def start(self):
current_time = time()
self.interval_start_time = current_time

def _set_current_step_name(self, step_name: str, current_time: float = None):
def _set_current_step_name(self, step_name: str, current_time: Optional[float] = None):
if step_name == self.current_step_name:
return
if current_time is None:
Expand All @@ -43,7 +43,7 @@ def _set_current_step_name(self, step_name: str, current_time: float = None):
self.current_step_name = step_name
self.current_step_start_time = current_time

def on_frame_start(self, initial_step_name: str = None):
def on_frame_start(self, initial_step_name: Optional[str] = None):
self.frame_start_time = time()
self.current_step_name = initial_step_name
self.current_step_start_time = self.frame_start_time
Expand Down