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

Adding SegGPT #27735

Merged
merged 122 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
fecf251
First commit
EduardoPach Nov 27, 2023
2fbf69b
Improvements
EduardoPach Nov 27, 2023
155e486
More improvements
EduardoPach Nov 27, 2023
2de229a
Converted original checkpoint to HF checkpoint
EduardoPach Nov 28, 2023
b3d5049
Fix style
EduardoPach Nov 28, 2023
fe53c92
Fixed forward
EduardoPach Nov 29, 2023
051b6c8
More improvements
EduardoPach Nov 30, 2023
70d0290
More improvements
EduardoPach Dec 5, 2023
951ac86
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Dec 7, 2023
14b70a7
Remove asserts
EduardoPach Dec 7, 2023
dce5f4a
Merge branch 'adding-seggpt' of https://github.com/EduardoPach/transf…
EduardoPach Dec 7, 2023
3c8e12a
Remove unnecessary attributes
EduardoPach Dec 7, 2023
449fa80
Changed model name to camel case
EduardoPach Dec 7, 2023
41e409b
Improve forward doc
EduardoPach Dec 7, 2023
3e0a77a
Improve tests
EduardoPach Dec 7, 2023
b039594
More improvements
EduardoPach Dec 7, 2023
5c604d4
Fix copies
EduardoPach Dec 7, 2023
00c8bda
Fix doc
EduardoPach Dec 7, 2023
dfc48dd
Make SegGptImageProcessor more flexible
EduardoPach Dec 7, 2023
4152a68
Added few-shot test
EduardoPach Dec 8, 2023
c04a177
Fix merge
NielsRogge Dec 10, 2023
acc58cc
Fix style
NielsRogge Dec 10, 2023
8bb30d5
Update READMEs and docs
NielsRogge Dec 10, 2023
6ec868b
Update READMEs
NielsRogge Dec 10, 2023
88e8144
Make inputs required
NielsRogge Dec 10, 2023
2a066e9
Add SegGptForImageSegmentation
NielsRogge Dec 11, 2023
09187e0
Make tests pass
EduardoPach Dec 12, 2023
5190205
Rename to out_indicies
EduardoPach Dec 12, 2023
bf0bab9
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Dec 13, 2023
c38de07
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Dec 13, 2023
52de2a7
Fixed naming convention
EduardoPach Dec 13, 2023
bebb958
Copying SegGptMlp from modeling_sam.py
EduardoPach Dec 13, 2023
2c7c311
Some minor improvements
NielsRogge Dec 12, 2023
75b2d90
Remove mlp_ratio
NielsRogge Dec 13, 2023
a612330
Fix docstrings
NielsRogge Dec 14, 2023
74383a8
Fixed docstring match
Jan 7, 2024
932a01f
Objects defined before use
Jan 7, 2024
f54d036
Storing only patch_size and beta for SegGptLoss
Jan 7, 2024
b283608
removed _prepare_inputs method
Jan 7, 2024
0fcfbcf
Removed modified from headers
Jan 7, 2024
64d2a90
Renamed to output_indicies
Jan 7, 2024
559c5be
Removed unnecessary einsums
Jan 7, 2024
45ce96b
Update tests/models/seggpt/test_modeling_seggpt.py
EduardoPach Jan 7, 2024
6f982aa
Update tests/models/seggpt/test_modeling_seggpt.py
EduardoPach Jan 7, 2024
c4d5c00
Update tests/models/seggpt/test_modeling_seggpt.py
EduardoPach Jan 7, 2024
6bc0571
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Jan 7, 2024
33c3f4d
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Jan 7, 2024
a435033
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Jan 7, 2024
798a7d3
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Jan 7, 2024
3b443dc
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Jan 7, 2024
e24c369
Fixing issues
Jan 7, 2024
bd0b552
Raise error as soon as possible
Jan 7, 2024
cca0937
More fixes
Jan 7, 2024
39e2767
Jan 7, 2024
3545672
Fix merge
NielsRogge Jan 14, 2024
7228221
Fix merge
NielsRogge Jan 14, 2024
6133e40
Added palette to SegGptImageProcessor
Jan 25, 2024
cf93d25
Merge branch 'adding-seggpt' of https://github.com/EduardoPach/transf…
Jan 25, 2024
1837324
Fixed typo
Jan 25, 2024
dc3cf80
Fixed shape typo
Jan 25, 2024
fc2304c
Added permute before doing palette to class mapping
Jan 25, 2024
b086384
Fixed style
Jan 26, 2024
0c9ad32
Fixed and added tests
Jan 26, 2024
beab961
Fixed docstrings
Jan 26, 2024
bd35b95
Matching SegFormer API for post_processing_semantic_segmentation
Feb 5, 2024
48d7fc3
Merge remote-tracking branch 'upstream/main' into adding-seggpt
Feb 5, 2024
3bcdf52
Fixed copies
Feb 5, 2024
900fac9
Fixed SegGptImageProcessor to handle both binary and RGB masks
Feb 5, 2024
abfc78a
Updated docstrings of SegGptImageProcessor
Feb 5, 2024
ba3f9cb
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Feb 7, 2024
09cdd0e
Update docs/source/en/model_doc/seggpt.md
EduardoPach Feb 7, 2024
690de06
Update src/transformers/models/seggpt/configuration_seggpt.py
EduardoPach Feb 7, 2024
37fabe2
Update src/transformers/models/seggpt/convert_seggpt_to_hf.py
EduardoPach Feb 7, 2024
a2a45cd
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Feb 7, 2024
59787c2
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Feb 7, 2024
cf3c1da
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Feb 7, 2024
706285f
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Feb 7, 2024
755a7b5
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Feb 7, 2024
c6257f5
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Feb 7, 2024
041c400
Update tests/models/seggpt/test_image_processing_seggpt.py
EduardoPach Feb 7, 2024
3ffecbc
Update tests/models/seggpt/test_modeling_seggpt.py
EduardoPach Feb 7, 2024
2d1d77c
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Feb 7, 2024
6354a60
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Feb 7, 2024
f5e23c2
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Feb 7, 2024
d347473
Object definitions above & fix style
Feb 7, 2024
9e35aa6
Renamed output_indices to intermediate_feature_indices
Feb 7, 2024
f6f068c
Removed unnecessary check on bool_masked_pos
Feb 7, 2024
a0cbe9b
Loss first in the outputs
Feb 7, 2024
f1dc953
Added validation for do_normalize
Feb 7, 2024
b8b1d5e
Improved SegGptImageProcessor and added new tests
Feb 10, 2024
d172ca0
Added comment
Feb 10, 2024
88db53f
Added docstrings to SegGptLoss
Feb 10, 2024
db06f21
Reimplemented ensemble condition logic in SegGptEncoder
Feb 10, 2024
5514650
Merge remote-tracking branch 'upstream/main' into adding-seggpt
Feb 10, 2024
7c4805e
Update src/transformers/models/seggpt/__init__.py
EduardoPach Feb 10, 2024
6ad819b
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Feb 10, 2024
9dab61f
Update src/transformers/models/seggpt/convert_seggpt_to_hf.py
EduardoPach Feb 10, 2024
1b87260
Update src/transformers/models/seggpt/configuration_seggpt.py
EduardoPach Feb 10, 2024
c74ca80
Updated docstrings to use post_process_semantic_segmentation
Feb 10, 2024
e5f2c8c
Merge branch 'adding-seggpt' of https://github.com/EduardoPach/transf…
Feb 10, 2024
71dfbf2
Merge remote-tracking branch 'upstream/main' into adding-seggpt
Feb 12, 2024
af21937
Fixed typo on docstrings
Feb 12, 2024
62a82eb
moved pixel values test to test_image_processing_seggpt
Feb 13, 2024
4d425df
Merge remote-tracking branch 'upstream/main' into adding-seggpt
Feb 15, 2024
460f3fa
Addressed comments
Feb 15, 2024
f62b21e
Update src/transformers/models/seggpt/configuration_seggpt.py
EduardoPach Feb 15, 2024
620381d
Update src/transformers/models/seggpt/image_processing_seggpt.py
EduardoPach Feb 15, 2024
9999d0b
Update src/transformers/models/seggpt/configuration_seggpt.py
EduardoPach Feb 15, 2024
b73b21e
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Feb 15, 2024
01c9f7e
Updated docstrings for SegGptLoss
Feb 15, 2024
c507557
Merge branch 'adding-seggpt' of https://github.com/EduardoPach/transf…
Feb 15, 2024
3373cbb
Address comments
Feb 15, 2024
f701039
Added SegGpt example to model docs
Feb 15, 2024
0e46681
Update src/transformers/models/seggpt/modeling_seggpt.py
EduardoPach Feb 21, 2024
43f2d34
moved patchify and unpatchify
EduardoPach Feb 21, 2024
ebc96f4
Merge remote-tracking branch 'upstream/main' into adding-seggpt
EduardoPach Feb 21, 2024
90f911d
Rename checkpoint
EduardoPach Feb 22, 2024
efb85d6
Renamed intermediate_features to intermediate_hidden_states for consi…
EduardoPach Feb 22, 2024
afeb9f2
Update src/transformers/models/seggpt/configuration_seggpt.py
EduardoPach Feb 22, 2024
7e22958
Replaced post_process_masks for post_process_semantic_segmentation in…
EduardoPach Feb 26, 2024
32dd142
Merge branch 'adding-seggpt' of https://github.com/EduardoPach/transf…
EduardoPach Feb 26, 2024
05f0a85
Merge remote-tracking branch 'upstream/main' into adding-seggpt
EduardoPach Feb 26, 2024
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
Prev Previous commit
Next Next commit
Renamed output_indices to intermediate_feature_indices
  • Loading branch information
Eduardo Pacheco committed Feb 7, 2024
commit 9e35aa6c27a7acea1a16ee4e5db71280f92b9d69
10 changes: 5 additions & 5 deletions src/transformers/models/seggpt/configuration_seggpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SegGptConfig(PretrainedConfig):
Whether to use relative position encoding in the Attention
EduardoPach marked this conversation as resolved.
Show resolved Hide resolved
merge_index (`int`, *optional*, defaults to 2):
The index of the encoder layer to merge the embeddings.
output_indicies (`List[int]`, *optional*, defaults to `[5, 11, 17, 23]`):
intermediate_feature_indices (`List[int]`, *optional*, defaults to `[5, 11, 17, 23]`):
The indices of the encoder layers which we store as features for the decoder.
beta (`float`, *optional*, defaults to 0.01):
Regularization factor for SegGptLoss (smooth-l1 loss).
Expand Down Expand Up @@ -114,15 +114,15 @@ def __init__(
decoder_hidden_size=64,
use_relative_position_embeddings=True,
merge_index=2,
output_indicies=[5, 11, 17, 23],
intermediate_feature_indices=[5, 11, 17, 23],
beta=0.01,
**kwargs,
):
super().__init__(**kwargs)

if merge_index > min(output_indicies):
if merge_index > min(intermediate_feature_indices):
raise ValueError(
f"Merge index must be less than the minimum encoder output index, but got {merge_index=} and {output_indicies=}"
f"Merge index must be less than the minimum encoder output index, but got {merge_index=} and {intermediate_feature_indices=}"
)
self.hidden_size = hidden_size
self.num_hidden_layers = num_hidden_layers
Expand All @@ -140,6 +140,6 @@ def __init__(
self.decoder_hidden_size = decoder_hidden_size
self.use_relative_position_embeddings = use_relative_position_embeddings
self.merge_index = merge_index
self.output_indicies = output_indicies
self.intermediate_feature_indices = intermediate_feature_indices
self.beta = beta
self.mlp_dim = int(hidden_size * 4) if mlp_dim is None else mlp_dim
8 changes: 4 additions & 4 deletions src/transformers/models/seggpt/modeling_seggpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class SegGptEncoderOutput(BaseModelOutput):
attentions (`Tuple[torch.FloatTensor]`, `optional`, returned when `config.output_attentions=True`):
Tuple of *torch.FloatTensor* (one for each layer) of shape
`(batch_size, num_heads, seq_len, seq_len)`.
intermediate_features (`Tuple[torch.FloatTensor]`, `optional`, returned when `config.output_indicies` is set):
intermediate_features (`Tuple[torch.FloatTensor]`, `optional`, returned when `config.intermediate_feature_indices` is set):
Tuple of `torch.FloatTensor` of shape `(batch_size, patch_height, patch_width, hidden_size)`.
Each element in the Tuple corresponds to the output of the layer specified in `config.output_indicies`.
Each element in the Tuple corresponds to the output of the layer specified in `config.intermediate_feature_indices`.
Additionaly, each feature passes through a LayerNorm.
"""

Expand Down Expand Up @@ -538,7 +538,7 @@ def forward(
hidden_states[: hidden_states.shape[0] // 2] + hidden_states[hidden_states.shape[0] // 2 :]
) * 0.5

if i in self.config.output_indicies:
if i in self.config.intermediate_feature_indices:
intermediate_features.append(self.layernorm(hidden_states))

if output_attentions:
Expand Down Expand Up @@ -620,7 +620,7 @@ class SegGptDecoder(nn.Module):
def __init__(self, config):
super().__init__()
self.decoder_embed = nn.Linear(
config.hidden_size * len(config.output_indicies),
config.hidden_size * len(config.intermediate_feature_indices),
config.patch_size**2 * config.decoder_hidden_size,
bias=True,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/models/seggpt/test_modeling_seggpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(
initializer_range=0.02,
mlp_ratio=2.0,
merge_index=0,
output_indicies=[1],
intermediate_feature_indices=[1],
pretrain_image_size=10,
decoder_hidden_size=10,
):
Expand All @@ -85,7 +85,7 @@ def __init__(
self.initializer_range = initializer_range
self.mlp_ratio = mlp_ratio
self.merge_index = merge_index
self.output_indicies = output_indicies
self.intermediate_feature_indices = intermediate_feature_indices
self.pretrain_image_size = pretrain_image_size
self.decoder_hidden_size = decoder_hidden_size

Expand Down Expand Up @@ -121,7 +121,7 @@ def get_config(self):
initializer_range=self.initializer_range,
mlp_ratio=self.mlp_ratio,
merge_index=self.merge_index,
output_indicies=self.output_indicies,
intermediate_feature_indices=self.intermediate_feature_indices,
pretrain_image_size=self.pretrain_image_size,
decoder_hidden_size=self.decoder_hidden_size,
)
Expand Down