pyCarDisplay.detection.midas package

Submodules

pyCarDisplay.detection.midas.base_model module

Reference:

“MiDaS,” Pytorch.org. [Online]. Available: https://pytorch.org/hub/intelisl_midas_v2/. [Accessed: 27-Mar-2021].

Original license from MiDaS code is below.

MIT License

Copyright (c) 2019 Intel ISL (Intel Intelligent Systems Lab)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pyCarDisplay.detection.midas.base_model.BaseModel[source]

Bases: torch.nn.modules.module.Module

Initializes internal Module state, shared by both nn.Module and ScriptModule.

load(path)[source]

Load model from file.

Args:

path (str): file path

training: bool

pyCarDisplay.detection.midas.blocks module

Reference:

“MiDaS,” Pytorch.org. [Online]. Available: https://pytorch.org/hub/intelisl_midas_v2/. [Accessed: 27-Mar-2021].

Original license from MiDaS code is below.

MIT License

Copyright (c) 2019 Intel ISL (Intel Intelligent Systems Lab)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pyCarDisplay.detection.midas.blocks.FeatureFusionBlock(features)[source]

Bases: torch.nn.modules.module.Module

Feature fusion block.

Init.

Args:

features (int): number of features

forward(*xs)[source]

Forward pass.

Returns:

tensor: output

training: bool
class pyCarDisplay.detection.midas.blocks.FeatureFusionBlock_custom(features, activation, deconv=False, bn=False, expand=False, align_corners=True)[source]

Bases: torch.nn.modules.module.Module

Feature fusion block.

Init.

Args:

features (int): number of features

forward(*xs)[source]

Forward pass.

Returns:

tensor: output

training: bool
class pyCarDisplay.detection.midas.blocks.Interpolate(scale_factor, mode)[source]

Bases: torch.nn.modules.module.Module

Interpolation module.

Init.

Args:

scale_factor (float): scaling mode (str): interpolation mode

forward(x)[source]

Forward pass.

Args:

x (tensor): input

Returns:

tensor: interpolated data

training: bool
class pyCarDisplay.detection.midas.blocks.ResidualConvUnit(features)[source]

Bases: torch.nn.modules.module.Module

Residual convolution module.

Init.

Args:

features (int): number of features

forward(x)[source]

Forward pass.

Args:

x (tensor): input

Returns:

tensor: output

training: bool
class pyCarDisplay.detection.midas.blocks.ResidualConvUnit_custom(features, activation, bn)[source]

Bases: torch.nn.modules.module.Module

Residual convolution module.

Init.

Args:

features (int): number of features

forward(x)[source]

Forward pass.

Args:

x (tensor): input

Returns:

tensor: output

training: bool

pyCarDisplay.detection.midas.midas_net module

MidashNet: Network for monocular depth estimation trained by mixing several datasets. The author of MiDaS adapted this code from https://github.com/thomasjpfan/pytorch_refinenet/blob/master/pytorch_refinenet/refinenet/refinenet_4cascade.py

Reference:

“MiDaS,” Pytorch.org. [Online]. Available: https://pytorch.org/hub/intelisl_midas_v2/. [Accessed: 27-Mar-2021].

Original license from MiDaS code is below.

MIT License

Copyright (c) 2019 Intel ISL (Intel Intelligent Systems Lab)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pyCarDisplay.detection.midas.midas_net.MidasNet(path=None, features=256, non_negative=True)[source]

Bases: pyCarDisplay.detection.midas.base_model.BaseModel

Network for monocular depth estimation.

Init.

Args:

path (str, optional): Path to saved model. Defaults to None. features (int, optional): Number of features. Defaults to 256. backbone (str, optional): Backbone network for encoder. Defaults to resnet50

forward(x)[source]

Forward pass.

Args:

x (tensor): input data (image)

Returns:

tensor: depth

training: bool

pyCarDisplay.detection.midas.midas_net_custom module

MidashNet: Network for monocular depth estimation trained by mixing several datasets. This file contains code that is adapted from https://github.com/thomasjpfan/pytorch_refinenet/blob/master/pytorch_refinenet/refinenet/refinenet_4cascade.py

Reference:

“MiDaS,” Pytorch.org. [Online]. Available: https://pytorch.org/hub/intelisl_midas_v2/. [Accessed: 27-Mar-2021].

Original license from MiDaS code is below.

MIT License

Copyright (c) 2019 Intel ISL (Intel Intelligent Systems Lab)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pyCarDisplay.detection.midas.midas_net_custom.MidasNet_small(path=None, features=64, backbone='efficientnet_lite3', non_negative=True, exportable=True, channels_last=False, align_corners=True, blocks={'expand': True})[source]

Bases: pyCarDisplay.detection.midas.base_model.BaseModel

Network for monocular depth estimation.

Init.

Args:

path (str, optional): Path to saved model. Defaults to None. features (int, optional): Number of features. Defaults to 256. backbone (str, optional): Backbone network for encoder. Defaults to resnet50

forward(x)[source]

Forward pass.

Args:

x (tensor): input data (image)

Returns:

tensor: depth

training: bool
pyCarDisplay.detection.midas.midas_net_custom.fuse_model(m)[source]

pyCarDisplay.detection.midas.transforms module

Reference:

“MiDaS,” Pytorch.org. [Online]. Available: https://pytorch.org/hub/intelisl_midas_v2/. [Accessed: 27-Mar-2021].

Original license from MiDaS code is below.

MIT License

Copyright (c) 2019 Intel ISL (Intel Intelligent Systems Lab)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class pyCarDisplay.detection.midas.transforms.NormalizeImage(mean, std)[source]

Bases: object

Normlize image by given mean and std.

class pyCarDisplay.detection.midas.transforms.PrepareForNet[source]

Bases: object

Prepare sample for usage as network input.

class pyCarDisplay.detection.midas.transforms.Resize(width, height, resize_target=True, keep_aspect_ratio=False, ensure_multiple_of=1, resize_method='lower_bound', image_interpolation_method=3)[source]

Bases: object

Resize sample to given size (width, height).

Init.

Args:

width (int): desired output width height (int): desired output height resize_target (bool, optional):

True: Resize the full sample (image, mask, target). False: Resize image only. Defaults to True.

keep_aspect_ratio (bool, optional):

True: Keep the aspect ratio of the input sample. Output sample might not have the given width and height, and resize behaviour depends on the parameter 'resize_method'. Defaults to False.

ensure_multiple_of (int, optional):

Output width and height is constrained to be multiple of this parameter. Defaults to 1.

resize_method (str, optional):

"lower_bound": Output will be at least as large as the given size. "upper_bound": Output will be at max as large as the given size. (Output size might be smaller than given size.) "minimal": Scale as least as possible. (Output size might be smaller than given size.) Defaults to "lower_bound".

constrain_to_multiple_of(x, min_val=0, max_val=None)[source]
get_size(width, height)[source]
pyCarDisplay.detection.midas.transforms.apply_min_size(sample, size, image_interpolation_method=3)[source]

Rezise the sample to ensure the given size. Keeps aspect ratio.

Args:

sample (dict): sample size (tuple): image size

Returns:

tuple: new size

Module contents