PUTvision / qgis-plugin-deepness

Deepness is a remote sensing plugin that enables deep learning inference in QGIS
https://www.buymeacoffee.com/deepness
Apache License 2.0
108 stars 25 forks source link

Model with multiple layers output #132

Closed tb-vhbc closed 8 months ago

tb-vhbc commented 10 months ago

When I try to use a segmentation model trained on Ultralytics (tutorial from git repo), I get this error in QGIS :

image

I understand that this is currently an unsupported feature. Nevertheless, is there an alternative or a workaround?

Regards,

tb-vhbc.

bartoszptak commented 10 months ago

Hi @tb-vhbc , You didn't attached configuration from the deepness window, so I can only suppose what could be wrong. If you train ULTRALYTICS yolov8 model for instance segmentation, you should use model type: Detector instead od Segmentor. Let me know if that helps you. Otherwise provide a screenshot of the deepness window, please

przemyslaw-aszkowski commented 10 months ago

Hi, If the above doesn't help, maybe it is something we saw earlier. Before exporting to ONNX, create a wrapper which selects only one output:

import torch
import torch.nn
class NewModel(nn.Module):
  def __init__(self, m):
    super().__init__()
    self.m = m
  def forward(self, x):
    x = self.m(x)
    return x['out']
model_new = NewModel(model)
x = torch.rand([1, 3, 256, 256])
_ = model_new(x)
tb-vhbc commented 10 months ago

Hi @bartoszptak

Below are the captures of deepness window :

image

image

And this the error output from QGIS :

NotImplementedError: Model with multiple output layers is not supported! Use only one output layer. 
Traceback (most recent call last):
  File "C:\Users/tb-vhbc/AppData/Roaming/QGIS/QGIS3\profiles\test-segmentation/python/plugins\deepness\deepness_dockwidget.py", line 264, in _browse_model_path
    self._load_model_and_display_info()
  File "C:\Users/tb-vhbc/AppData/Roaming/QGIS/QGIS3\profiles\test-segmentation/python/plugins\deepness\deepness_dockwidget.py", line 385, in _load_model_and_display_info
    self._update_model_output_format_mapping()
  File "C:\Users/tb-vhbc/AppData/Roaming/QGIS/QGIS3\profiles\test-segmentation/python/plugins\deepness\deepness_dockwidget.py", line 393, in _update_model_output_format_mapping
    for output_number in range(self._model.get_number_of_output_channels()):
  File "C:\Users/tb-vhbc/AppData/Roaming/QGIS/QGIS3\profiles\test-segmentation/python/plugins\deepness\processing\models\segmentor.py", line 77, in get_number_of_output_channels
    raise NotImplementedError("Model with multiple output layers is not supported! Use only one output layer.")
NotImplementedError: Model with multiple output layers is not supported! Use only one output layer.

Version de Python : 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] 
Version de QGIS : 3.32.1-Lima Lima, 4a078ecf63 
przemyslaw-aszkowski commented 10 months ago

Hi, as Bartosz wrote, please use Detector instead od Segmentor model type