Skip to content
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

Add depth estimation pipeline #18618

Merged
merged 13 commits into from
Oct 12, 2022

Conversation

nandwalritik
Copy link
Contributor

@nandwalritik nandwalritik commented Aug 14, 2022

What does this PR do?

Fixes #18446

Before submitting

Who can review?

@NielsRogge @Narsil

Error While using the pipeline

pipe = pipeline("depth-estimation")
No model was supplied, defaulted to Intel/dpt-large and revision e93beec (https://huggingface.co/Intel/dpt-large).
Using a pipeline without specifying a model name and revision in production is not recommended.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/pipelines/__init__.py", line 670, in pipeline
    framework, model = infer_framework_load_model(
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/pipelines/base.py", line 257, in infer_framework_load_model
    model = model_class.from_pretrained(model, **kwargs)
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/models/auto/auto_factory.py", line 445, in from_pretrained
    model_class = _get_model_class(config, cls._model_mapping)
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/models/auto/auto_factory.py", line 359, in _get_model_class
    supported_models = model_mapping[type(config)]
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/models/auto/auto_factory.py", line 565, in __getitem__
    return self._load_attr_from_module(model_type, model_name)
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/models/auto/auto_factory.py", line 579, in _load_attr_from_module
    return getattribute_from_module(self._modules[module_name], attr)
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/models/auto/auto_factory.py", line 539, in getattribute_from_module
    return getattribute_from_module(transformers_module, attr)
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/models/auto/auto_factory.py", line 539, in getattribute_from_module
    return getattribute_from_module(transformers_module, attr)
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/models/auto/auto_factory.py", line 539, in getattribute_from_module
    return getattribute_from_module(transformers_module, attr)
  [Previous line repeated 982 more times]
  File "/home/nandwalritik/nandwalritik/transformers/src/transformers/models/auto/auto_factory.py", line 538, in getattribute_from_module
    transformers_module = importlib.import_module("transformers")
  File "/home/nandwalritik/anaconda3/envs/hftfSwinDev/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1004, in _find_and_load
  File "<frozen importlib._bootstrap>", line 157, in __enter__
  File "<frozen importlib._bootstrap>", line 183, in _get_module_lock
  File "<frozen importlib._bootstrap>", line 59, in __init__
RecursionError: maximum recursion depth exceeded while calling a Python object

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Aug 14, 2022

The documentation is not available anymore as the PR was closed or merged.

@nandwalritik nandwalritik force-pushed the add_depth_estimation_pipeline branch from 143d331 to fed82a2 Compare August 15, 2022 04:57
@nandwalritik
Copy link
Contributor Author

nandwalritik commented Aug 15, 2022

Hi @NielsRogge @Narsil I tried debugging to resolve above issue, I found that in src/transformers/models/auto/auto_factory.py in line 462 model_class = _get_model_class(config, cls._model_mapping) when I logged cls._model_mapping I recieved

OrderedDict([(<class 'transformers...PTConfig'>, <?>), (<class 'transformers...PNConfig'>, <?>)])
<error>:
Traceback (most recent call last):

Can you guide me to resolve this error.

Copy link
Contributor

@Narsil Narsil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR, you also need to add

+    def _sanitize_parameters(self, **kwargs):
+        return {}, {}, {}
+

To the pipeline, it's not used but the base class expects this method to exist. (Here there's not parameters declared so it's quite easy.

This weird method exist to allow parameters to be defined both at definition time or call tiime

pipe = pipeline(model=model, myargs=1)
data = pipe(image)
# or
pipe = pipeline(model=model)
data = pipe(image, myargs=1)

Cheers !
Otherwise LGTM.

Why do you output 3 different images ? That sounds like a lot.

The image I can understand, the predicted depth is defined in what unit ? Is it noisy hence the interpolation ?
IMO that seems like something to be left to the user to decide what to do.

In general I think a pure image would be nice (to be a bit more general) but I can understand that the loss of precision might be harmful, do you mind sharing how you use those numbers ? Maybe we could output an other time of image that doesn't loose information (keeping f32 pixel)

Wdyt ?

@nandwalritik nandwalritik force-pushed the add_depth_estimation_pipeline branch 2 times, most recently from 930d335 to e80aadd Compare September 1, 2022 03:54
@nandwalritik
Copy link
Contributor Author

nandwalritik commented Sep 1, 2022

Great PR, you also need to add

+    def _sanitize_parameters(self, **kwargs):
+        return {}, {}, {}
+

To the pipeline, it's not used but the base class expects this method to exist. (Here there's not parameters declared so it's quite easy.

This weird method exist to allow parameters to be defined both at definition time or call tiime

pipe = pipeline(model=model, myargs=1)
data = pipe(image)
# or
pipe = pipeline(model=model)
data = pipe(image, myargs=1)

Cheers ! Otherwise LGTM.

Why do you output 3 different images ? That sounds like a lot.

The image I can understand, the predicted depth is defined in what unit ? Is it noisy hence the interpolation ? IMO that seems like something to be left to the user to decide what to do.

In general I think a pure image would be nice (to be a bit more general) but I can understand that the loss of precision might be harmful, do you mind sharing how you use those numbers ? Maybe we could output an other time of image that doesn't loose information (keeping f32 pixel)

Wdyt ?

I just saw DPT's depth estimation example and added these three outputs. I have removed the interpolation one and In the output I have kept only the predicted_depth (which is a tensor) and depth (which is the PIL Image object).
Let me know if I should remove the predicted_depth also.

Copy link
Contributor

@Narsil Narsil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Aside from the missing generic test.
Would you like us to write it ? (It's not too hard to write I think).

My biggest question is why depth-estimation needs it's own pipeline.

I understand in the robotics context you really want something that's not an image, but really a matrix with depth (expressed iin meters I guess).
This reason only makes me ok with the idea of creating this pipeline as is.

But ideally it would be nice if the output was an image (so it could become image-generation) with either an output that would be trivial to transform into a depth map or a parameter.

@mishig25 maybe for advice ideas on the widget that could be different than an image/generation here ?

In any case, expect if anyone has better ideas counterarguments, we should just merge this right now (after having the generic test), and maybe later convert this to an alias if we decide to merge.

@nandwalritik nandwalritik force-pushed the add_depth_estimation_pipeline branch from 9d57e01 to df4ed06 Compare September 5, 2022 04:07
@nandwalritik
Copy link
Contributor Author

Review required

At least 1 approving review is required by reviewers with write access. Learn more.
** 1 pending reviewer **

By generic test did you mean run_pipeline_test ? Let me know if it's other than this, I have added run_pipeline_test for now.
Also In CI test_pipelines_depth_estimation is failing can you help me with that ?

@nandwalritik nandwalritik requested review from Narsil and removed request for NielsRogge and Narsil September 7, 2022 08:15
@nandwalritik nandwalritik force-pushed the add_depth_estimation_pipeline branch from 5d97e03 to 7d5dd21 Compare September 15, 2022 10:20
@github-actions
Copy link

github-actions bot commented Oct 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@NielsRogge
Copy link
Contributor

Hi @nandwalritik, could you revive this PR by rebasing with the main branch?

@nandwalritik nandwalritik force-pushed the add_depth_estimation_pipeline branch from c5e7df6 to 0a1fb70 Compare October 10, 2022 11:47
@nandwalritik
Copy link
Contributor Author

Hi @nandwalritik, could you revive this PR by rebasing with the main branch?

Done.

@Narsil
Copy link
Contributor

Narsil commented Oct 10, 2022

@nandwalritik Do you want to help to get the PR green ?

@nandwalritik
Copy link
Contributor Author

@nandwalritik Do you want to help to get the PR green ?

@Narsil Yeah please , I tried but I was not able to make the test cases pass.

Copy link
Contributor

@Narsil Narsil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments on how I fixed the CI for you.

Comment on lines 28 to 32
<<<<<<< HEAD
- [`DocumentQuestionAnsweringPipeline`]
=======
- [`DepthEstimationPipeline`]
>>>>>>> Add initial files for depth estimation pipelines
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a leftover from a bad rebase I think, I removed those lines and put back the documentation in alphabetical order.

### DocumentQuestionAnsweringPipeline

[[autodoc]] DocumentQuestionAnsweringPipeline
- __call__
- all

=======
### DepthEstimationPipeline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -1,7 +1,6 @@
from typing import List, Union

import numpy as np
import torch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

torch is not a mandatory dependency, we need to import it only when it's OK to do so.

@@ -32,6 +30,9 @@
from .test_pipelines_common import ANY, PipelineTestCaseMeta


if is_torch_available():
import torch
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same in tests.

require_vision,
slow,
)
from transformers.testing_utils import nested_simplify, require_tf, require_timm, require_torch, require_vision, slow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you create your PR and today we removed is_pipeline_test as we're now passing on these tests based on directory not by ENV variable.

@nandwalritik
Copy link
Contributor Author

Added some comments on how I fixed the CI for you.

Thanks I will look at them.

@Narsil Narsil force-pushed the add_depth_estimation_pipeline branch from 4fd5e5f to 31a08bd Compare October 11, 2022 12:22
@Narsil
Copy link
Contributor

Narsil commented Oct 11, 2022

@sgugger for final review.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks a lot for your work on this!

docs/source/en/main_classes/pipelines.mdx Outdated Show resolved Hide resolved
@Narsil
Copy link
Contributor

Narsil commented Oct 12, 2022

@sgugger the test failure seem unrelated to the PR, should we go ahead and merge ?

@sgugger
Copy link
Collaborator

sgugger commented Oct 12, 2022

Yes, those are flaky tests.

@sgugger sgugger merged commit e94384e into huggingface:main Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add depth estimation pipeline
5 participants