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 ZoeDepth #30136

Open
wants to merge 92 commits into
base: main
Choose a base branch
from
Open

Add ZoeDepth #30136

wants to merge 92 commits into from

Conversation

NielsRogge
Copy link
Contributor

@NielsRogge NielsRogge commented Apr 9, 2024

What does this PR do?

This PR adds ZoeDepth as introduced in ZoeDepth: Zero-shot Transfer by Combining Relative and Metric Depth.

To do:

  • double check image processor (not sure we can support the same resize). Update image processor accordingly
  • remove testing scripts
  • verify relative position bias table/index when loading a beit model from the hub
  • add slow integration test
  • add image processor tests
  • should we add backbone_hidden_size?
  • make doc tests pass

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@ydshieh
Copy link
Collaborator

ydshieh commented May 3, 2024

Fixed #30634

@NielsRogge
Copy link
Contributor Author

Hi @amyeroberts addressed all comments, CI is green

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for the continued work on this!

There's still a few structural pieces to tidy up, but looking close to merge!

src/transformers/models/zoedepth/configuration_zoedepth.py Outdated Show resolved Hide resolved
outputs = model(**inputs)
predicted_depth = outputs.predicted_depth

# interpolate to original size
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is to be done in a follow-up, an issue should be made to make sure it's actually done

... predicted_depth = outputs.predicted_depth

>>> # interpolate to original size
>>> prediction = torch.nn.functional.interpolate(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Has an issue / feature request been opened?

src/transformers/models/zoedepth/modeling_zoedepth.py Outdated Show resolved Hide resolved
src/transformers/models/zoedepth/modeling_zoedepth.py Outdated Show resolved Hide resolved
src/transformers/models/zoedepth/modeling_zoedepth.py Outdated Show resolved Hide resolved
return self.log_binomial_transform(probabilities, temperature)


class ZoeDepthSeedBinRegressor(nn.Module):
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would have them in one class in the attractor. There's already a lot of if/else logic in the forward pass, I don't think this would make much of a difference. Up to you depending on whether you care more about the consistency or not

src/transformers/models/zoedepth/modeling_zoedepth.py Outdated Show resolved Hide resolved
src/transformers/models/beit/modeling_beit.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for the work adding this model! Looks nearly ready to merge.

A few final things to do before:

  • Run slow tests for beit and data2vec. This can be done through pushing an empty commit [run-slow] beit data2vec
  • Run the doc examples and confirm (with screenshot?) that they're passing
  • Clarify the norming logic

The final bit that needs to be confirmed/addressed is making sure that this model doesn't suffer from the same issues that have been seen in the DPT model #28292 (as some of this is copied from) i.e. the model shouldn't create weights that never used.


def test_keep_aspect_ratio(self):
size = {"height": 512, "width": 512}
image_processor = ZoeDepthImageProcessor(size=size, keep_aspect_ratio=True, ensure_multiple_of=32)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It shouldn't be necessary to have to look at that function to figure out how these arguments interact - this should be made clear in the docstring. In particular, which one takes precedence.

This still needs to be tested here for different combinations. At the moment keep_aspect_ratio=False is untested

src/transformers/models/zoedepth/modeling_zoedepth.py Outdated Show resolved Hide resolved
@NielsRogge
Copy link
Contributor Author

Ok,

Pushed an empty commit to run the slow tests which confirmed all slow test are passing, the doc tests are tested by the build_pr_documentation check right?

@amyeroberts
Copy link
Collaborator

the doc tests are tested by the build_pr_documentation check right?

No, this checks the documentation can be built i.e. the webpage.

See: https://huggingface.co/docs/transformers/main/en/testing#run-documentation-tests

@NielsRogge
Copy link
Contributor Author

NielsRogge commented May 28, 2024

Sorry I meant the tests_pr_documentation_tests check (which is passing)

@amyeroberts
Copy link
Collaborator

Ah, yes, that should be fine as long as the docs and model examples are tested. The only thing is from the recent CI workflow, it doesn't look like the tests have properly run (?). At least, it's not possible to see which tests have run at all there

@NielsRogge
Copy link
Contributor Author

@amyeroberts feel free to approve the PR as all comments have been addressed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants