index int64 0 50.7k | project_path stringclasses 279
values | completion_path stringlengths 57 199 | signature_postion stringlengths 3 11 | class_position stringlengths 3 11 | function_name stringlengths 1 62 | class_name stringlengths 0 55 | body_position stringlengths 3 11 | body_position_with_comments stringlengths 3 11 | masked_class stringlengths 14 8.32k | masked_class_with_comment stringlengths 14 8.32k | func_body stringlengths 9 6.72k | func_body_with_comment stringlengths 9 6.72k | len_func_body int64 1 643 | len_input int64 10 2.02k | len_output int64 4 1.9k | total int64 20 2.05k | file_code stringlengths 14 442k | file_code_with_comment stringlengths 14 442k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
50,613 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything/modeling/transformer.py | 62,68 | 16,109 | forward | TwoWayTransformer | 81,109 | 68,109 | class TwoWayTransformer(nn.Module):
def __init__(
self,
depth: int,
embedding_dim: int,
num_heads: int,
mlp_dim: int,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
) -> None:
"""
A transformer decoder that atten... | class TwoWayTransformer(nn.Module):
def __init__(
self,
depth: int,
embedding_dim: int,
num_heads: int,
mlp_dim: int,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
) -> None:
"""
A transformer decoder that atten... | # BxCxHxW -> BxHWxC == B x N_image_tokens x C
bs, c, h, w = image_embedding.shape
image_embedding = image_embedding.flatten(2).permute(0, 2, 1)
image_pe = image_pe.flatten(2).permute(0, 2, 1)
# Prepare queries
queries = point_embedding
keys = image_embedding
... | """
Args:
image_embedding (torch.Tensor): image to attend to. Should be shape
B x embedding_dim x h x w for any h and w.
image_pe (torch.Tensor): the positional encoding to add to the image. Must
have the same shape as image_embedding.
point_embeddin... | 93 | 675 | 320 | 995 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,615 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything/utils/transforms.py | 55,56 | 16,103 | apply_image_torch | ResizeLongestSide | 61,67 | 56,67 | class ResizeLongestSide:
"""
Resizes images to the longest side 'target_length', as well as provides
methods for resizing coordinates and boxes. Provides methods for
transforming both numpy array and batched torch tensors.
"""
def __init__(self, target_length: int) -> None:
self.target_... | class ResizeLongestSide:
"""
Resizes images to the longest side 'target_length', as well as provides
methods for resizing coordinates and boxes. Provides methods for
transforming both numpy array and batched torch tensors.
"""
def __init__(self, target_length: int) -> None:
self.target_... | # Expects an image in BCHW format. May not exactly match apply_image.
target_size = self.get_preprocess_shape(image.shape[2], image.shape[3], self.target_length)
return F.interpolate(
image, target_size, mode="bilinear", align_corners=False, antialias=True
)
| """
Expects batched images with shape BxCxHxW and float format. This
transformation may not exactly match apply_image. apply_image is
the transformation expected by the model.
"""
# Expects an image in BCHW format. May not exactly match apply_image.
target_size = ... | 25 | 1,105 | 102 | 1,207 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... |
50,617 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/build_sam.py | 54,55 | 1,148 | _apply_eval_dtype_sam | 55,67 | 55,67 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... |
def prep_model(model, dtype):
if dtype is not None:
return model.eval().to(dtype)
return model.eval()
model.image_encoder = prep_model(model.image_encoder, dtype)
model.prompt_encoder = prep_model(model.prompt_encoder, dtype)
model.mask_decoder = prep_model(model.mask_decod... |
def prep_model(model, dtype):
if dtype is not None:
return model.eval().to(dtype)
return model.eval()
model.image_encoder = prep_model(model.image_encoder, dtype)
model.prompt_encoder = prep_model(model.prompt_encoder, dtype)
model.mask_decoder = prep_model(model.mask_decod... | 26 | 1,475 | 131 | 1,606 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... | |
50,619 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/modeling/common.py | 38,39 | 31,44 | forward | LayerNorm2d | 39,44 | 39,44 | class LayerNorm2d(nn.Module):
def __init__(self, num_channels: int, eps: float = 1e-6) -> None:
super().__init__()
self.weight = nn.Parameter(torch.ones(num_channels))
self.bias = nn.Parameter(torch.zeros(num_channels))
self.eps = eps
def forward(self, x: torch.Tensor) -> torch.... | class LayerNorm2d(nn.Module):
def __init__(self, num_channels: int, eps: float = 1e-6) -> None:
super().__init__()
self.weight = nn.Parameter(torch.ones(num_channels))
self.bias = nn.Parameter(torch.zeros(num_channels))
self.eps = eps
def forward(self, x: torch.Tensor) -> torch.... | u = x.mean(-3, keepdim=True)
s = (x - u).pow(2).mean(-3, keepdim=True)
x = (x - u) / torch.sqrt(s + self.eps)
x = self.weight[:, None, None] * x + self.bias[:, None, None]
return x
| u = x.mean(-3, keepdim=True)
s = (x - u).pow(2).mean(-3, keepdim=True)
x = (x - u) / torch.sqrt(s + self.eps)
x = self.weight[:, None, None] * x + self.bias[:, None, None]
return x
| 32 | 135 | 93 | 228 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... |
50,620 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/modeling/common.py | 25,26 | 13,31 | forward | MLPBlock | 26,31 | 26,31 | class MLPBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
mlp_dim: int,
act: Type[nn.Module] = nn.GELU,
) -> None:
super().__init__()
self.lin1 = nn.Linear(embedding_dim, mlp_dim)
self.lin2 = nn.Linear(mlp_dim, embedding_dim)
self.act = ac... | class MLPBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
mlp_dim: int,
act: Type[nn.Module] = nn.GELU,
) -> None:
super().__init__()
self.lin1 = nn.Linear(embedding_dim, mlp_dim)
self.lin2 = nn.Linear(mlp_dim, embedding_dim)
self.act = ac... | return self.lin2(self.act(self.lin1(x)))
# From https://github.com/facebookresearch/detectron2/blob/main/detectron2/layers/batch_norm.py # noqa
# Itself from https://github.com/facebookresearch/ConvNeXt/blob/d1fa8f6fef0a165b27399986cc2bdacc92777e40/models/convnext.py#L119 # noqa
| return self.lin2(self.act(self.lin1(x)))
# From https://github.com/facebookresearch/detectron2/blob/main/detectron2/layers/batch_norm.py # noqa
# Itself from https://github.com/facebookresearch/ConvNeXt/blob/d1fa8f6fef0a165b27399986cc2bdacc92777e40/models/convnext.py#L119 # noqa
| 13 | 155 | 138 | 293 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... |
50,621 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/modeling/prompt_encoder.py | 206,207 | 192,234 | _pe_encoding | PositionEmbeddingRandom | 208,215 | 207,215 | class PositionEmbeddingRandom(nn.Module):
"""
Positional encoding using random spatial frequencies.
"""
def __init__(self, num_pos_feats: int = 64, scale: Optional[float] = None) -> None:
super().__init__()
if scale is None or scale <= 0.0:
scale = 1.0
self.register_... | class PositionEmbeddingRandom(nn.Module):
"""
Positional encoding using random spatial frequencies.
"""
def __init__(self, num_pos_feats: int = 64, scale: Optional[float] = None) -> None:
super().__init__()
if scale is None or scale <= 0.0:
scale = 1.0
self.register_... | # assuming coords are in [0, 1]^2 square and have d_1 x ... x d_n x 2 shape
coords = 2 * coords - 1
coords = coords.to(self.positional_encoding_gaussian_matrix.dtype) @ self.positional_encoding_gaussian_matrix
coords = 2 * np.pi * coords
# outputs d_1 x ... x d_n x C shape
... | """Positionally encode points that are normalized to [0,1]."""
# assuming coords are in [0, 1]^2 square and have d_1 x ... x d_n x 2 shape
coords = 2 * coords - 1
coords = coords.to(self.positional_encoding_gaussian_matrix.dtype) @ self.positional_encoding_gaussian_matrix
coords ... | 51 | 509 | 148 | 657 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch import nn
from typing import Any, Optional, Tuple, Type
from .common import L... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch import nn
from typing import Any, Optional, Tuple, Type
from .common import L... |
50,623 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/modeling/transformer.py | 215,216 | 184,234 | forward | Attention | 216,234 | 216,234 | class Attention(nn.Module):
"""
An attention layer that allows for downscaling the size of the embedding
after projection to queries, keys, and values.
"""
def __init__(
self,
embedding_dim: int,
num_heads: int,
downsample_rate: int = 1,
) -> None:
super(... | class Attention(nn.Module):
"""
An attention layer that allows for downscaling the size of the embedding
after projection to queries, keys, and values.
"""
def __init__(
self,
embedding_dim: int,
num_heads: int,
downsample_rate: int = 1,
) -> None:
super(... | # Input projections
q = self.q_proj(q)
k = self.k_proj(k)
v = self.v_proj(v)
# Separate into heads
q = self._separate_heads(q, self.num_heads)
k = self._separate_heads(k, self.num_heads)
v = self._separate_heads(v, self.num_heads)
# Attention
... | # Input projections
q = self.q_proj(q)
k = self.k_proj(k)
v = self.v_proj(v)
# Separate into heads
q = self._separate_heads(q, self.num_heads)
k = self._separate_heads(k, self.num_heads)
v = self._separate_heads(v, self.num_heads)
# Attention
... | 46 | 431 | 203 | 634 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,624 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/modeling/transformer.py | 150,153 | 108,184 | forward | TwoWayAttentionBlock | 153,184 | 153,184 | class TwoWayAttentionBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
num_heads: int,
mlp_dim: int = 2048,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
skip_first_layer_pe: bool = False,
) -> None:
"""
... | class TwoWayAttentionBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
num_heads: int,
mlp_dim: int = 2048,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
skip_first_layer_pe: bool = False,
) -> None:
"""
... | # Self attention block
if self.skip_first_layer_pe:
queries = self.self_attn(q=queries, k=queries, v=queries)
else:
q = queries + query_pe
attn_out = self.self_attn(q=q, k=q, v=queries)
queries = queries + attn_out
queries = self.norm1(quer... | # Self attention block
if self.skip_first_layer_pe:
queries = self.self_attn(q=queries, k=queries, v=queries)
else:
q = queries + query_pe
attn_out = self.self_attn(q=q, k=q, v=queries)
queries = queries + attn_out
queries = self.norm1(quer... | 111 | 552 | 361 | 913 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,625 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/modeling/transformer.py | 62,68 | 16,108 | forward | TwoWayTransformer | 81,108 | 68,108 | class TwoWayTransformer(nn.Module):
def __init__(
self,
depth: int,
embedding_dim: int,
num_heads: int,
mlp_dim: int,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
) -> None:
"""
A transformer decoder that atten... | class TwoWayTransformer(nn.Module):
def __init__(
self,
depth: int,
embedding_dim: int,
num_heads: int,
mlp_dim: int,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
) -> None:
"""
A transformer decoder that atten... | # BxCxHxW -> BxHWxC == B x N_image_tokens x C
image_embedding = image_embedding.flatten(-2).transpose(-1, -2)
image_pe = image_pe.flatten(-2).transpose(-1, -2)
# Prepare queries
queries = point_embedding
keys = image_embedding
# Apply transformer blocks and fina... | """
Args:
image_embedding (torch.Tensor): image to attend to. Should be shape
B x embedding_dim x h x w for any h and w.
image_pe (torch.Tensor): the positional encoding to add to the image. Must
have the same shape as image_embedding.
point_embeddin... | 85 | 675 | 294 | 969 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,626 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/sparse.py | 6,7 | 1,33 | apply_fake_sparsity | 11,28 | 7,28 | import torch
from torch.sparse import to_sparse_semi_structured, SparseSemiStructuredTensor
SparseSemiStructuredTensor._FORCE_CUTLASS = True
# Sparsity helper functions
def apply_fake_sparsity(model):
FILL_FUNC_BODYdef apply_sparse(model):
apply_fake_sparsity(model)
for name, mod in model.named_modules():
... | import torch
from torch.sparse import to_sparse_semi_structured, SparseSemiStructuredTensor
SparseSemiStructuredTensor._FORCE_CUTLASS = True
# Sparsity helper functions
def apply_fake_sparsity(model):
"""
This function simulates 2:4 sparsity on all linear layers in a model.
It uses the torch.ao.pruning flo... | # torch.ao.pruning flow
from torch.ao.pruning import WeightNormSparsifier
sparse_config = []
for name, mod in model.named_modules():
if isinstance(mod, torch.nn.Linear):
sparse_config.append({"tensor_fqn": f"{name}.weight"})
sparsifier = WeightNormSparsifier(sparsity_level=1.0,
... | """
This function simulates 2:4 sparsity on all linear layers in a model.
It uses the torch.ao.pruning flow.
"""
# torch.ao.pruning flow
from torch.ao.pruning import WeightNormSparsifier
sparse_config = []
for name, mod in model.named_modules():
if isinstance(mod, torch.nn.Linear... | 30 | 198 | 195 | 393 | import torch
from torch.sparse import to_sparse_semi_structured, SparseSemiStructuredTensor
SparseSemiStructuredTensor._FORCE_CUTLASS = True
# Sparsity helper functions
def apply_fake_sparsity(model):
FILL_FUNC_BODYdef apply_sparse(model):
apply_fake_sparsity(model)
for name, mod in model.named_modules():
... | import torch
from torch.sparse import to_sparse_semi_structured, SparseSemiStructuredTensor
SparseSemiStructuredTensor._FORCE_CUTLASS = True
# Sparsity helper functions
def apply_fake_sparsity(model):
"""
This function simulates 2:4 sparsity on all linear layers in a model.
It uses the torch.ao.pruning flo... | |
50,627 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/tools.py | 1,4 | 1,37 | replace_with_custom_fn_if_matches_filter | 8,22 | 4,22 | def replace_with_custom_fn_if_matches_filter(
model, replacement_fn, filter_fn, cur_fqn=''
) -> None:
FILL_FUNC_BODYdef apply_eval_dtype_predictor(predictor, dtype=None):
def prep_model(model, dtype):
if dtype is not None:
return model.eval().to(dtype)
return model.eval()
predi... | def replace_with_custom_fn_if_matches_filter(
model, replacement_fn, filter_fn, cur_fqn=''
) -> None:
"""
For each `child` in `model`, replaces it with `replacement_fn(child)`
if `filter_fn(child)` is `True`
"""
FILL_FUNC_BODYdef apply_eval_dtype_predictor(predictor, dtype=None):
def prep_model... | name_to_child = dict(model.named_children())
for name, child in name_to_child.items():
if cur_fqn == '':
new_fqn = name
else:
new_fqn = f'{cur_fqn}.{name}'
if filter_fn(child, new_fqn):
new_child = replacement_fn(child)
setattr(model, name,... | """
For each `child` in `model`, replaces it with `replacement_fn(child)`
if `filter_fn(child)` is `True`
"""
name_to_child = dict(model.named_children())
for name, child in name_to_child.items():
if cur_fqn == '':
new_fqn = name
else:
new_fqn = f'{cur_fqn... | 34 | 261 | 170 | 431 | def replace_with_custom_fn_if_matches_filter(
model, replacement_fn, filter_fn, cur_fqn=''
) -> None:
FILL_FUNC_BODYdef apply_eval_dtype_predictor(predictor, dtype=None):
def prep_model(model, dtype):
if dtype is not None:
return model.eval().to(dtype)
return model.eval()
predi... | def replace_with_custom_fn_if_matches_filter(
model, replacement_fn, filter_fn, cur_fqn=''
) -> None:
"""
For each `child` in `model`, replaces it with `replacement_fn(child)`
if `filter_fn(child)` is `True`
"""
FILL_FUNC_BODYdef apply_eval_dtype_predictor(predictor, dtype=None):
def prep_model... | |
50,628 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_fast/utils/transforms.py | 47,48 | 16,103 | apply_boxes | ResizeLongestSide | 52,55 | 48,55 | class ResizeLongestSide:
"""
Resizes images to the longest side 'target_length', as well as provides
methods for resizing coordinates and boxes. Provides methods for
transforming both numpy array and batched torch tensors.
"""
def __init__(self, target_length: int) -> None:
self.target_... | class ResizeLongestSide:
"""
Resizes images to the longest side 'target_length', as well as provides
methods for resizing coordinates and boxes. Provides methods for
transforming both numpy array and batched torch tensors.
"""
def __init__(self, target_length: int) -> None:
self.target_... | boxes = self.apply_coords(boxes.reshape(-1, 2, 2), original_size)
return boxes.reshape(-1, 4)
| """
Expects a numpy array shape Bx4. Requires the original image size
in (H, W) format.
"""
boxes = self.apply_coords(boxes.reshape(-1, 2, 2), original_size)
return boxes.reshape(-1, 4)
| 9 | 1,158 | 46 | 1,204 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... |
50,630 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/build_sam.py | 47,48 | 1,168 | build_sam_vit_t | 48,100 | 48,100 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoderHQ, PromptEncoder, Sam, Two... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoderHQ, PromptEncoder, Sam, Two... | prompt_embed_dim = 256
image_size = 1024
vit_patch_size = 16
image_embedding_size = image_size // vit_patch_size
mobile_sam = Sam(
image_encoder=TinyViT(img_size=1024, in_chans=3, num_classes=1000,
embed_dims=[64, 128, 160, 320],
depths=[2, 2, 6, 2],
... | prompt_embed_dim = 256
image_size = 1024
vit_patch_size = 16
image_embedding_size = image_size // vit_patch_size
mobile_sam = Sam(
image_encoder=TinyViT(img_size=1024, in_chans=3, num_classes=1000,
embed_dims=[64, 128, 160, 320],
depths=[2, 2, 6, 2],
... | 127 | 1,258 | 758 | 2,016 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoderHQ, PromptEncoder, Sam, Two... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoderHQ, PromptEncoder, Sam, Two... | |
50,631 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/build_sam_baseline.py | 47,48 | 1,157 | build_sam_vit_t | 48,95 | 48,95 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... | prompt_embed_dim = 256
image_size = 1024
vit_patch_size = 16
image_embedding_size = image_size // vit_patch_size
mobile_sam = Sam(
image_encoder=TinyViT(img_size=1024, in_chans=3, num_classes=1000,
embed_dims=[64, 128, 160, 320],
depths=[2, 2, 6, 2],
... | prompt_embed_dim = 256
image_size = 1024
vit_patch_size = 16
image_embedding_size = image_size // vit_patch_size
mobile_sam = Sam(
image_encoder=TinyViT(img_size=1024, in_chans=3, num_classes=1000,
embed_dims=[64, 128, 160, 320],
depths=[2, 2, 6, 2],
... | 88 | 1,136 | 633 | 1,769 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from functools import partial
from .modeling import ImageEncoderViT, MaskDecoder, PromptEncoder, Sam, TwoWa... | |
50,632 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/common.py | 38,39 | 31,44 | forward | LayerNorm2d | 39,44 | 39,44 | class LayerNorm2d(nn.Module):
def __init__(self, num_channels: int, eps: float = 1e-6) -> None:
super().__init__()
self.weight = nn.Parameter(torch.ones(num_channels))
self.bias = nn.Parameter(torch.zeros(num_channels))
self.eps = eps
def forward(self, x: torch.Tensor) -> torch.... | class LayerNorm2d(nn.Module):
def __init__(self, num_channels: int, eps: float = 1e-6) -> None:
super().__init__()
self.weight = nn.Parameter(torch.ones(num_channels))
self.bias = nn.Parameter(torch.zeros(num_channels))
self.eps = eps
def forward(self, x: torch.Tensor) -> torch.... | u = x.mean(1, keepdim=True)
s = (x - u).pow(2).mean(1, keepdim=True)
x = (x - u) / torch.sqrt(s + self.eps)
x = self.weight[:, None, None] * x + self.bias[:, None, None]
return x
| u = x.mean(1, keepdim=True)
s = (x - u).pow(2).mean(1, keepdim=True)
x = (x - u) / torch.sqrt(s + self.eps)
x = self.weight[:, None, None] * x + self.bias[:, None, None]
return x
| 32 | 135 | 93 | 228 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... |
50,633 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/common.py | 25,26 | 13,31 | forward | MLPBlock | 26,31 | 26,31 | class MLPBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
mlp_dim: int,
act: Type[nn.Module] = nn.GELU,
) -> None:
super().__init__()
self.lin1 = nn.Linear(embedding_dim, mlp_dim)
self.lin2 = nn.Linear(mlp_dim, embedding_dim)
self.act = ac... | class MLPBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
mlp_dim: int,
act: Type[nn.Module] = nn.GELU,
) -> None:
super().__init__()
self.lin1 = nn.Linear(embedding_dim, mlp_dim)
self.lin2 = nn.Linear(mlp_dim, embedding_dim)
self.act = ac... | return self.lin2(self.act(self.lin1(x)))
# From https://github.com/facebookresearch/detectron2/blob/main/detectron2/layers/batch_norm.py # noqa
# Itself from https://github.com/facebookresearch/ConvNeXt/blob/d1fa8f6fef0a165b27399986cc2bdacc92777e40/models/convnext.py#L119 # noqa
| return self.lin2(self.act(self.lin1(x)))
# From https://github.com/facebookresearch/detectron2/blob/main/detectron2/layers/batch_norm.py # noqa
# Itself from https://github.com/facebookresearch/ConvNeXt/blob/d1fa8f6fef0a165b27399986cc2bdacc92777e40/models/convnext.py#L119 # noqa
| 13 | 155 | 138 | 293 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... |
50,635 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/image_encoder.py | 227,228 | 188,246 | forward | Attention | 228,246 | 228,246 | class Attention(nn.Module):
"""Multi-head Attention block with relative position embeddings."""
def __init__(
self,
dim: int,
num_heads: int = 8,
qkv_bias: bool = True,
use_rel_pos: bool = False,
rel_pos_zero_init: bool = True,
input_size: Optional[Tuple[... | class Attention(nn.Module):
"""Multi-head Attention block with relative position embeddings."""
def __init__(
self,
dim: int,
num_heads: int = 8,
qkv_bias: bool = True,
use_rel_pos: bool = False,
rel_pos_zero_init: bool = True,
input_size: Optional[Tuple[... | B, H, W, _ = x.shape
# qkv with shape (3, B, nHead, H * W, C)
qkv = self.qkv(x).reshape(B, H * W, 3, self.num_heads, -1).permute(2, 0, 3, 1, 4)
# q, k, v with shape (B * nHead, H * W, C)
q, k, v = qkv.reshape(3, B * self.num_heads, H * W, -1).unbind(0)
attn = (q * self.s... | B, H, W, _ = x.shape
# qkv with shape (3, B, nHead, H * W, C)
qkv = self.qkv(x).reshape(B, H * W, 3, self.num_heads, -1).permute(2, 0, 3, 1, 4)
# q, k, v with shape (B * nHead, H * W, C)
q, k, v = qkv.reshape(3, B * self.num_heads, H * W, -1).unbind(0)
attn = (q * self.s... | 99 | 516 | 341 | 857 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,636 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/image_encoder.py | 169,170 | 122,188 | forward | Block | 170,188 | 170,188 | class Block(nn.Module):
"""Transformer blocks with support of window attention and residual propagation blocks"""
def __init__(
self,
dim: int,
num_heads: int,
mlp_ratio: float = 4.0,
qkv_bias: bool = True,
norm_layer: Type[nn.Module] = nn.LayerNorm,
act_... | class Block(nn.Module):
"""Transformer blocks with support of window attention and residual propagation blocks"""
def __init__(
self,
dim: int,
num_heads: int,
mlp_ratio: float = 4.0,
qkv_bias: bool = True,
norm_layer: Type[nn.Module] = nn.LayerNorm,
act_... | shortcut = x
x = self.norm1(x)
# Window partition
if self.window_size > 0:
H, W = x.shape[1], x.shape[2]
x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x)
# Reverse window partition
if self.window_size > 0:
x =... | shortcut = x
x = self.norm1(x)
# Window partition
if self.window_size > 0:
H, W = x.shape[1], x.shape[2]
x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x)
# Reverse window partition
if self.window_size > 0:
x =... | 53 | 615 | 178 | 793 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,637 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/image_encoder.py | 106,107 | 17,122 | forward | ImageEncoderViT | 107,122 | 107,122 | class ImageEncoderViT(nn.Module):
def __init__(
self,
img_size: int = 1024,
patch_size: int = 16,
in_chans: int = 3,
embed_dim: int = 768,
depth: int = 12,
num_heads: int = 12,
mlp_ratio: float = 4.0,
out_chans: int = 256,
qkv_bias: boo... | class ImageEncoderViT(nn.Module):
def __init__(
self,
img_size: int = 1024,
patch_size: int = 16,
in_chans: int = 3,
embed_dim: int = 768,
depth: int = 12,
num_heads: int = 12,
mlp_ratio: float = 4.0,
out_chans: int = 256,
qkv_bias: boo... | x = self.patch_embed(x)
if self.pos_embed is not None:
x = x + self.pos_embed
interm_embeddings=[]
for blk in self.blocks:
x = blk(x)
if blk.window_size == 0:
interm_embeddings.append(x)
x = self.neck(x.permute(0, 3, 1, 2))
... | x = self.patch_embed(x)
if self.pos_embed is not None:
x = x + self.pos_embed
interm_embeddings=[]
for blk in self.blocks:
x = blk(x)
if blk.window_size == 0:
interm_embeddings.append(x)
x = self.neck(x.permute(0, 3, 1, 2))
... | 35 | 1,041 | 143 | 1,184 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,638 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/image_encoder.py | 394,395 | 367,399 | forward | PatchEmbed | 395,399 | 395,399 | class PatchEmbed(nn.Module):
"""
Image to Patch Embedding.
"""
def __init__(
self,
kernel_size: Tuple[int, int] = (16, 16),
stride: Tuple[int, int] = (16, 16),
padding: Tuple[int, int] = (0, 0),
in_chans: int = 3,
embed_dim: int = 768,
) -> None:
... | class PatchEmbed(nn.Module):
"""
Image to Patch Embedding.
"""
def __init__(
self,
kernel_size: Tuple[int, int] = (16, 16),
stride: Tuple[int, int] = (16, 16),
padding: Tuple[int, int] = (0, 0),
in_chans: int = 3,
embed_dim: int = 768,
) -> None:
... | x = self.proj(x)
# B C H W -> B H W C
x = x.permute(0, 2, 3, 1)
return x
| x = self.proj(x)
# B C H W -> B H W C
x = x.permute(0, 2, 3, 1)
return x
| 21 | 301 | 52 | 353 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,639 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/mask_decoder.py | 173,174 | 156,179 | forward | MLP | 174,179 | 174,179 | class MLP(nn.Module):
def __init__(
self,
input_dim: int,
hidden_dim: int,
output_dim: int,
num_layers: int,
sigmoid_output: bool = False,
) -> None:
super().__init__()
self.num_layers = num_layers
h = [hidden_dim] * (num_layers - 1)
... | class MLP(nn.Module):
def __init__(
self,
input_dim: int,
hidden_dim: int,
output_dim: int,
num_layers: int,
sigmoid_output: bool = False,
) -> None:
super().__init__()
self.num_layers = num_layers
h = [hidden_dim] * (num_layers - 1)
... | for i, layer in enumerate(self.layers):
x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
if self.sigmoid_output:
x = F.sigmoid(x)
return x
| for i, layer in enumerate(self.layers):
x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
if self.sigmoid_output:
x = F.sigmoid(x)
return x
| 23 | 189 | 75 | 264 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... |
50,640 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/mask_decoder.py | 71,81 | 16,156 | forward | MaskDecoder | 96,114 | 81,114 | class MaskDecoder(nn.Module):
def __init__(
self,
*,
transformer_dim: int,
transformer: nn.Module,
num_multimask_outputs: int = 3,
activation: Type[nn.Module] = nn.GELU,
iou_head_depth: int = 3,
iou_head_hidden_dim: int = 256,
) -> None:
""... | class MaskDecoder(nn.Module):
def __init__(
self,
*,
transformer_dim: int,
transformer: nn.Module,
num_multimask_outputs: int = 3,
activation: Type[nn.Module] = nn.GELU,
iou_head_depth: int = 3,
iou_head_hidden_dim: int = 256,
) -> None:
""... | masks, iou_pred = self.predict_masks(
image_embeddings=image_embeddings,
image_pe=image_pe,
sparse_prompt_embeddings=sparse_prompt_embeddings,
dense_prompt_embeddings=dense_prompt_embeddings,
)
# Select the correct mask or masks for output
... | """
Predict masks given image and prompt embeddings.
Arguments:
image_embeddings (torch.Tensor): the embeddings from the image encoder
image_pe (torch.Tensor): positional encoding with the shape of image_embeddings
sparse_prompt_embeddings (torch.Tensor): the embed... | 45 | 1,626 | 201 | 1,827 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... |
50,641 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/mask_decoder_hq.py | 227,228 | 210,233 | forward | MLP | 228,233 | 228,233 | class MLP(nn.Module):
def __init__(
self,
input_dim: int,
hidden_dim: int,
output_dim: int,
num_layers: int,
sigmoid_output: bool = False,
) -> None:
super().__init__()
self.num_layers = num_layers
h = [hidden_dim] * (num_layers - 1)
... | class MLP(nn.Module):
def __init__(
self,
input_dim: int,
hidden_dim: int,
output_dim: int,
num_layers: int,
sigmoid_output: bool = False,
) -> None:
super().__init__()
self.num_layers = num_layers
h = [hidden_dim] * (num_layers - 1)
... | for i, layer in enumerate(self.layers):
x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
if self.sigmoid_output:
x = F.sigmoid(x)
return x
| for i, layer in enumerate(self.layers):
x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
if self.sigmoid_output:
x = F.sigmoid(x)
return x
| 23 | 189 | 75 | 264 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# Modified by HQ-SAM team
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List,... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# Modified by HQ-SAM team
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List,... |
50,643 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/prompt_encoder.py | 196,197 | 182,227 | _pe_encoding | PositionEmbeddingRandom | 198,206 | 197,206 | class PositionEmbeddingRandom(nn.Module):
"""
Positional encoding using random spatial frequencies.
"""
def __init__(self, num_pos_feats: int = 64, scale: Optional[float] = None) -> None:
super().__init__()
if scale is None or scale <= 0.0:
scale = 1.0
self.register_... | class PositionEmbeddingRandom(nn.Module):
"""
Positional encoding using random spatial frequencies.
"""
def __init__(self, num_pos_feats: int = 64, scale: Optional[float] = None) -> None:
super().__init__()
if scale is None or scale <= 0.0:
scale = 1.0
self.register_... | # assuming coords are in [0, 1]^2 square and have d_1 x ... x d_n x 2 shape
coords = 2 * coords - 1
coords = coords.to(self.positional_encoding_gaussian_matrix.dtype)
coords = coords @ self.positional_encoding_gaussian_matrix
coords = 2 * np.pi * coords
# outputs d_1 x ..... | """Positionally encode points that are normalized to [0,1]."""
# assuming coords are in [0, 1]^2 square and have d_1 x ... x d_n x 2 shape
coords = 2 * coords - 1
coords = coords.to(self.positional_encoding_gaussian_matrix.dtype)
coords = coords @ self.positional_encoding_gaussia... | 54 | 558 | 156 | 714 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch import nn
from typing import Any, Optional, Tuple, Type
from .common import L... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch import nn
from typing import Any, Optional, Tuple, Type
from .common import L... |
50,646 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 260,261 | 212,287 | forward | Attention | 261,287 | 261,287 | class Attention(torch.nn.Module):
def __init__(self, dim, key_dim, num_heads=8,
attn_ratio=4,
resolution=(14, 14),
):
super().__init__()
# (h, w)
assert isinstance(resolution, tuple) and len(resolution) == 2
self.num_heads = num_head... | class Attention(torch.nn.Module):
def __init__(self, dim, key_dim, num_heads=8,
attn_ratio=4,
resolution=(14, 14),
):
super().__init__()
# (h, w)
assert isinstance(resolution, tuple) and len(resolution) == 2
self.num_heads = num_head... | B, N, _ = x.shape
# Normalization
x = self.norm(x)
qkv = self.qkv(x)
# (B, N, num_heads, d)
q, k, v = qkv.view(B, N, self.num_heads, -
1).split([self.key_dim, self.key_dim, self.d], dim=3)
# (B, num_heads, N, d)
q = q.permute(0... | B, N, _ = x.shape
# Normalization
x = self.norm(x)
qkv = self.qkv(x)
# (B, N, num_heads, d)
q, k, v = qkv.view(B, N, self.num_heads, -
1).split([self.key_dim, self.key_dim, self.d], dim=3)
# (B, num_heads, N, d)
q = q.permute(0... | 86 | 606 | 338 | 944 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,647 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 436,437 | 383,449 | forward | BasicLayer | 437,446 | 437,446 | class BasicLayer(nn.Module):
""" A basic TinyViT layer for one stage.
Args:
dim (int): Number of input channels.
input_resolution (tuple[int]): Input resolution.
depth (int): Number of blocks.
num_heads (int): Number of attention heads.
window_size (int): Local window si... | class BasicLayer(nn.Module):
""" A basic TinyViT layer for one stage.
Args:
dim (int): Number of input channels.
input_resolution (tuple[int]): Input resolution.
depth (int): Number of blocks.
num_heads (int): Number of attention heads.
window_size (int): Local window si... | for blk in self.blocks:
if self.use_checkpoint:
x = checkpoint.checkpoint(blk, x)
else:
x = blk(x)
if self.downsample is not None:
x = self.downsample(x)
return x
| for blk in self.blocks:
if self.use_checkpoint:
x = checkpoint.checkpoint(blk, x)
else:
x = blk(x)
if self.downsample is not None:
x = self.downsample(x)
return x
| 24 | 671 | 84 | 755 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,648 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 32,34 | 21,46 | fuse | Conv2d_BN | 34,46 | 34,46 | class Conv2d_BN(torch.nn.Sequential):
def __init__(self, a, b, ks=1, stride=1, pad=0, dilation=1,
groups=1, bn_weight_init=1):
super().__init__()
self.add_module('c', torch.nn.Conv2d(
a, b, ks, stride, pad, dilation, groups, bias=False))
bn = torch.nn.BatchNorm2d... | class Conv2d_BN(torch.nn.Sequential):
def __init__(self, a, b, ks=1, stride=1, pad=0, dilation=1,
groups=1, bn_weight_init=1):
super().__init__()
self.add_module('c', torch.nn.Conv2d(
a, b, ks, stride, pad, dilation, groups, bias=False))
bn = torch.nn.BatchNorm2d... | c, bn = self._modules.values()
w = bn.weight / (bn.running_var + bn.eps)**0.5
w = c.weight * w[:, None, None, None]
b = bn.bias - bn.running_mean * bn.weight / \
(bn.running_var + bn.eps)**0.5
m = torch.nn.Conv2d(w.size(1) * self.c.groups, w.size(
0), w.sh... | c, bn = self._modules.values()
w = bn.weight / (bn.running_var + bn.eps)**0.5
w = c.weight * w[:, None, None, None]
b = bn.bias - bn.running_mean * bn.weight / \
(bn.running_var + bn.eps)**0.5
m = torch.nn.Conv2d(w.size(1) * self.c.groups, w.size(
0), w.sh... | 47 | 214 | 217 | 431 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,649 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 178,179 | 150,189 | forward | ConvLayer | 179,189 | 179,189 | class ConvLayer(nn.Module):
def __init__(self, dim, input_resolution, depth,
activation,
drop_path=0., downsample=None, use_checkpoint=False,
out_dim=None,
conv_expand_ratio=4.,
):
super().__init__()
self.dim = dim... | class ConvLayer(nn.Module):
def __init__(self, dim, input_resolution, depth,
activation,
drop_path=0., downsample=None, use_checkpoint=False,
out_dim=None,
conv_expand_ratio=4.,
):
super().__init__()
self.dim = dim... | for blk in self.blocks:
if self.use_checkpoint:
x = checkpoint.checkpoint(blk, x)
else:
x = blk(x)
if self.downsample is not None:
x = self.downsample(x)
return x
| for blk in self.blocks:
if self.use_checkpoint:
x = checkpoint.checkpoint(blk, x)
else:
x = blk(x)
if self.downsample is not None:
x = self.downsample(x)
return x
| 24 | 273 | 86 | 359 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,650 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 456,457 | 449,462 | forward | LayerNorm2d | 457,462 | 457,462 | class LayerNorm2d(nn.Module):
def __init__(self, num_channels: int, eps: float = 1e-6) -> None:
super().__init__()
self.weight = nn.Parameter(torch.ones(num_channels))
self.bias = nn.Parameter(torch.zeros(num_channels))
self.eps = eps
def forward(self, x: torch.Tensor) -> torch.... | class LayerNorm2d(nn.Module):
def __init__(self, num_channels: int, eps: float = 1e-6) -> None:
super().__init__()
self.weight = nn.Parameter(torch.ones(num_channels))
self.bias = nn.Parameter(torch.zeros(num_channels))
self.eps = eps
def forward(self, x: torch.Tensor) -> torch.... | u = x.mean(1, keepdim=True)
s = (x - u).pow(2).mean(1, keepdim=True)
x = (x - u) / torch.sqrt(s + self.eps)
x = self.weight[:, None, None] * x + self.bias[:, None, None]
return x
| u = x.mean(1, keepdim=True)
s = (x - u).pow(2).mean(1, keepdim=True)
x = (x - u) / torch.sqrt(s + self.eps)
x = self.weight[:, None, None] * x + self.bias[:, None, None]
return x
| 32 | 135 | 93 | 228 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,651 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 99,100 | 77,118 | forward | MBConv | 100,118 | 100,118 | class MBConv(nn.Module):
def __init__(self, in_chans, out_chans, expand_ratio,
activation, drop_path):
super().__init__()
self.in_chans = in_chans
self.hidden_chans = int(in_chans * expand_ratio)
self.out_chans = out_chans
self.conv1 = Conv2d_BN(in_chans, se... | class MBConv(nn.Module):
def __init__(self, in_chans, out_chans, expand_ratio,
activation, drop_path):
super().__init__()
self.in_chans = in_chans
self.hidden_chans = int(in_chans * expand_ratio)
self.out_chans = out_chans
self.conv1 = Conv2d_BN(in_chans, se... | shortcut = x
x = self.conv1(x)
x = self.act1(x)
x = self.conv2(x)
x = self.act2(x)
x = self.conv3(x)
x = self.drop_path(x)
x += shortcut
x = self.act3(x)
return x
| shortcut = x
x = self.conv1(x)
x = self.act1(x)
x = self.conv2(x)
x = self.act2(x)
x = self.conv3(x)
x = self.drop_path(x)
x += shortcut
x = self.act3(x)
return x
| 29 | 303 | 118 | 421 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,652 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 201,202 | 189,212 | forward | Mlp | 202,212 | 202,212 | class Mlp(nn.Module):
def __init__(self, in_features, hidden_features=None,
out_features=None, act_layer=nn.GELU, drop=0.):
super().__init__()
out_features = out_features or in_features
hidden_features = hidden_features or in_features
self.norm = nn.LayerNorm(in_feat... | class Mlp(nn.Module):
def __init__(self, in_features, hidden_features=None,
out_features=None, act_layer=nn.GELU, drop=0.):
super().__init__()
out_features = out_features or in_features
hidden_features = hidden_features or in_features
self.norm = nn.LayerNorm(in_feat... | x = self.norm(x)
x = self.fc1(x)
x = self.act(x)
x = self.drop(x)
x = self.fc2(x)
x = self.drop(x)
return x
| x = self.norm(x)
x = self.fc1(x)
x = self.act(x)
x = self.drop(x)
x = self.fc2(x)
x = self.drop(x)
return x
| 20 | 184 | 79 | 263 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,653 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 73,74 | 57,77 | forward | PatchEmbed | 74,77 | 74,77 | class PatchEmbed(nn.Module):
def __init__(self, in_chans, embed_dim, resolution, activation):
super().__init__()
img_size: Tuple[int, int] = to_2tuple(resolution)
self.patches_resolution = (img_size[0] // 4, img_size[1] // 4)
self.num_patches = self.patches_resolution[0] * \
... | class PatchEmbed(nn.Module):
def __init__(self, in_chans, embed_dim, resolution, activation):
super().__init__()
img_size: Tuple[int, int] = to_2tuple(resolution)
self.patches_resolution = (img_size[0] // 4, img_size[1] // 4)
self.num_patches = self.patches_resolution[0] * \
... | return self.seq(x)
| return self.seq(x)
| 2 | 248 | 14 | 262 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,654 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 133,134 | 118,150 | forward | PatchMerging | 134,150 | 134,150 | class PatchMerging(nn.Module):
def __init__(self, input_resolution, dim, out_dim, activation):
super().__init__()
self.input_resolution = input_resolution
self.dim = dim
self.out_dim = out_dim
self.act = activation()
self.conv1 = Conv2d_BN(dim, out_dim, 1, 1, 0)
... | class PatchMerging(nn.Module):
def __init__(self, input_resolution, dim, out_dim, activation):
super().__init__()
self.input_resolution = input_resolution
self.dim = dim
self.out_dim = out_dim
self.act = activation()
self.conv1 = Conv2d_BN(dim, out_dim, 1, 1, 0)
... | if x.ndim == 3:
H, W = self.input_resolution
B = len(x)
# (B, C, H, W)
x = x.view(B, H, W, -1).permute(0, 3, 1, 2)
x = self.conv1(x)
x = self.act(x)
x = self.conv2(x)
x = self.act(x)
x = self.conv3(x)
x = x.flatten... | if x.ndim == 3:
H, W = self.input_resolution
B = len(x)
# (B, C, H, W)
x = x.view(B, H, W, -1).permute(0, 3, 1, 2)
x = self.conv1(x)
x = self.act(x)
x = self.conv2(x)
x = self.act(x)
x = self.conv3(x)
x = x.flatten... | 46 | 241 | 169 | 410 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,655 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 600,601 | 462,629 | forward_features | TinyViT | 601,621 | 601,621 | class TinyViT(nn.Module):
def __init__(self, img_size=224, in_chans=3, num_classes=1000,
embed_dims=[96, 192, 384, 768], depths=[2, 2, 6, 2],
num_heads=[3, 6, 12, 24],
window_sizes=[7, 7, 14, 7],
mlp_ratio=4.,
drop_rate=0.,
... | class TinyViT(nn.Module):
def __init__(self, img_size=224, in_chans=3, num_classes=1000,
embed_dims=[96, 192, 384, 768], depths=[2, 2, 6, 2],
num_heads=[3, 6, 12, 24],
window_sizes=[7, 7, 14, 7],
mlp_ratio=4.,
drop_rate=0.,
... | # x: (N, C, H, W)
x = self.patch_embed(x)
x = self.layers[0](x)
start_i = 1
interm_embeddings=[]
for i in range(start_i, len(self.layers)):
layer = self.layers[i]
x = layer(x)
# print('x shape:', x.shape, '---i:', i)
if i ... | # x: (N, C, H, W)
x = self.patch_embed(x)
x = self.layers[0](x)
start_i = 1
interm_embeddings=[]
for i in range(start_i, len(self.layers)):
layer = self.layers[i]
x = layer(x)
# print('x shape:', x.shape, '---i:', i)
if i ... | 56 | 1,730 | 245 | 1,975 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,656 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/tiny_vit_sam.py | 335,336 | 287,383 | forward | TinyViTBlock | 336,378 | 336,378 | class TinyViTBlock(nn.Module):
r""" TinyViT Block.
Args:
dim (int): Number of input channels.
input_resolution (tuple[int, int]): Input resolution.
num_heads (int): Number of attention heads.
window_size (int): Window size.
mlp_ratio (float): Ratio of mlp hidden dim to e... | class TinyViTBlock(nn.Module):
r""" TinyViT Block.
Args:
dim (int): Number of input channels.
input_resolution (tuple[int, int]): Input resolution.
num_heads (int): Number of attention heads.
window_size (int): Window size.
mlp_ratio (float): Ratio of mlp hidden dim to e... | H, W = self.input_resolution
B, L, C = x.shape
assert L == H * W, "input feature has wrong size"
res_x = x
if H == self.window_size and W == self.window_size:
x = self.attn(x)
else:
x = x.view(B, H, W, C)
pad_b = (self.window_size - H %... | H, W = self.input_resolution
B, L, C = x.shape
assert L == H * W, "input feature has wrong size"
res_x = x
if H == self.window_size and W == self.window_size:
x = self.attn(x)
else:
x = x.view(B, H, W, C)
pad_b = (self.window_size - H %... | 177 | 692 | 571 | 1,263 | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... | # --------------------------------------------------------
# TinyViT Model Architecture
# Copyright (c) 2022 Microsoft
# Adapted from LeViT and Swin Transformer
# LeViT: (https://github.com/facebookresearch/levit)
# Swin: (https://github.com/microsoft/swin-transformer)
# Build the TinyViT Model
# ------------------... |
50,657 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/transformer.py | 218,219 | 185,241 | forward | Attention | 219,241 | 219,241 | class Attention(nn.Module):
"""
An attention layer that allows for downscaling the size of the embedding
after projection to queries, keys, and values.
"""
def __init__(
self,
embedding_dim: int,
num_heads: int,
downsample_rate: int = 1,
) -> None:
super(... | class Attention(nn.Module):
"""
An attention layer that allows for downscaling the size of the embedding
after projection to queries, keys, and values.
"""
def __init__(
self,
embedding_dim: int,
num_heads: int,
downsample_rate: int = 1,
) -> None:
super(... | # Input projections
q = self.q_proj(q)
k = self.k_proj(k)
v = self.v_proj(v)
# Separate into heads
q = self._separate_heads(q, self.num_heads)
k = self._separate_heads(k, self.num_heads)
v = self._separate_heads(v, self.num_heads)
# Attention
... | # Input projections
q = self.q_proj(q)
k = self.k_proj(k)
v = self.v_proj(v)
# Separate into heads
q = self._separate_heads(q, self.num_heads)
k = self._separate_heads(k, self.num_heads)
v = self._separate_heads(v, self.num_heads)
# Attention
... | 77 | 494 | 281 | 775 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,658 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/transformer.py | 151,154 | 109,185 | forward | TwoWayAttentionBlock | 154,185 | 154,185 | class TwoWayAttentionBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
num_heads: int,
mlp_dim: int = 2048,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
skip_first_layer_pe: bool = False,
) -> None:
"""
... | class TwoWayAttentionBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
num_heads: int,
mlp_dim: int = 2048,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
skip_first_layer_pe: bool = False,
) -> None:
"""
... | # Self attention block
if self.skip_first_layer_pe:
queries = self.self_attn(q=queries, k=queries, v=queries)
else:
q = queries + query_pe
attn_out = self.self_attn(q=q, k=q, v=queries)
queries = queries + attn_out
queries = self.norm1(quer... | # Self attention block
if self.skip_first_layer_pe:
queries = self.self_attn(q=queries, k=queries, v=queries)
else:
q = queries + query_pe
attn_out = self.self_attn(q=q, k=q, v=queries)
queries = queries + attn_out
queries = self.norm1(quer... | 111 | 552 | 361 | 913 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,659 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/modeling/transformer.py | 62,68 | 16,109 | forward | TwoWayTransformer | 81,109 | 68,109 | class TwoWayTransformer(nn.Module):
def __init__(
self,
depth: int,
embedding_dim: int,
num_heads: int,
mlp_dim: int,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
) -> None:
"""
A transformer decoder that atten... | class TwoWayTransformer(nn.Module):
def __init__(
self,
depth: int,
embedding_dim: int,
num_heads: int,
mlp_dim: int,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
) -> None:
"""
A transformer decoder that atten... | # BxCxHxW -> BxHWxC == B x N_image_tokens x C
bs, c, h, w = image_embedding.shape
image_embedding = image_embedding.flatten(2).permute(0, 2, 1)
image_pe = image_pe.flatten(2).permute(0, 2, 1)
# Prepare queries
queries = point_embedding
keys = image_embedding
... | """
Args:
image_embedding (torch.Tensor): image to attend to. Should be shape
B x embedding_dim x h x w for any h and w.
image_pe (torch.Tensor): the positional encoding to add to the image. Must
have the same shape as image_embedding.
point_embeddin... | 93 | 675 | 320 | 995 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,661 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_hq/utils/transforms.py | 93,95 | 16,103 | get_preprocess_shape | ResizeLongestSide | 98,103 | 95,103 | class ResizeLongestSide:
"""
Resizes images to the longest side 'target_length', as well as provides
methods for resizing coordinates and boxes. Provides methods for
transforming both numpy array and batched torch tensors.
"""
def __init__(self, target_length: int) -> None:
self.target_... | class ResizeLongestSide:
"""
Resizes images to the longest side 'target_length', as well as provides
methods for resizing coordinates and boxes. Provides methods for
transforming both numpy array and batched torch tensors.
"""
def __init__(self, target_length: int) -> None:
self.target_... | scale = long_side_length * 1.0 / max(oldh, oldw)
newh, neww = oldh * scale, oldw * scale
neww = int(neww + 0.5)
newh = int(newh + 0.5)
return (newh, neww)
| """
Compute the output size given input size and target long side length.
"""
scale = long_side_length * 1.0 / max(oldh, oldw)
newh, neww = oldh * scale, oldw * scale
neww = int(neww + 0.5)
newh = int(newh + 0.5)
return (newh, neww)
| 30 | 1,123 | 83 | 1,206 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... |
50,664 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/common.py | 38,39 | 31,46 | forward | LayerNorm2d | 39,46 | 39,46 | class LayerNorm2d(nn.Module):
def __init__(self, num_channels: int, eps: float = 1e-6) -> None:
super().__init__()
self.weight = nn.Parameter(torch.ones(num_channels))
self.bias = nn.Parameter(torch.zeros(num_channels))
self.eps = eps
def forward(self, x: torch.Tensor) -> torch.... | class LayerNorm2d(nn.Module):
def __init__(self, num_channels: int, eps: float = 1e-6) -> None:
super().__init__()
self.weight = nn.Parameter(torch.ones(num_channels))
self.bias = nn.Parameter(torch.zeros(num_channels))
self.eps = eps
def forward(self, x: torch.Tensor) -> torch.... | u = x.mean(1, keepdim=True)
s = (x - u).pow(2).mean(1, keepdim=True)
x = (x - u) / torch.sqrt(s + self.eps)
y = self.weight[:, None, None] * x
# y = torch.mul(self.weight[:, None, None], x)
x = y + self.bias[:, None, None]
return x
| u = x.mean(1, keepdim=True)
s = (x - u).pow(2).mean(1, keepdim=True)
x = (x - u) / torch.sqrt(s + self.eps)
y = self.weight[:, None, None] * x
# y = torch.mul(self.weight[:, None, None], x)
x = y + self.bias[:, None, None]
return x
| 42 | 135 | 122 | 257 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... |
50,665 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/common.py | 25,26 | 13,31 | forward | MLPBlock | 26,31 | 26,31 | class MLPBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
mlp_dim: int,
act: Type[nn.Module] = nn.GELU,
) -> None:
super().__init__()
self.lin1 = nn.Linear(embedding_dim, mlp_dim)
self.lin2 = nn.Linear(mlp_dim, embedding_dim)
self.act = ac... | class MLPBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
mlp_dim: int,
act: Type[nn.Module] = nn.GELU,
) -> None:
super().__init__()
self.lin1 = nn.Linear(embedding_dim, mlp_dim)
self.lin2 = nn.Linear(mlp_dim, embedding_dim)
self.act = ac... | return self.lin2(self.act(self.lin1(x)))
# From https://github.com/facebookresearch/detectron2/blob/main/detectron2/layers/batch_norm.py # noqa
# Itself from https://github.com/facebookresearch/ConvNeXt/blob/d1fa8f6fef0a165b27399986cc2bdacc92777e40/models/convnext.py#L119 # noqa
| return self.lin2(self.act(self.lin1(x)))
# From https://github.com/facebookresearch/detectron2/blob/main/detectron2/layers/batch_norm.py # noqa
# Itself from https://github.com/facebookresearch/ConvNeXt/blob/d1fa8f6fef0a165b27399986cc2bdacc92777e40/models/convnext.py#L119 # noqa
| 13 | 155 | 138 | 293 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... |
50,667 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/image_encoder.py | 43,44 | 18,59 | forward | Adapter_Layer | 44,59 | 44,59 | class Adapter_Layer(nn.Module):
def __init__(self, embed_dim, mlp_ratio=0.25, norm_layer = nn.LayerNorm, skip_connect=True):
super().__init__()
self.skip_connect = skip_connect
hidden_dim = int(embed_dim * mlp_ratio)
self.norm = norm_layer(embed_dim)
self.avg_pool = nn.Adapti... | class Adapter_Layer(nn.Module):
def __init__(self, embed_dim, mlp_ratio=0.25, norm_layer = nn.LayerNorm, skip_connect=True):
super().__init__()
self.skip_connect = skip_connect
hidden_dim = int(embed_dim * mlp_ratio)
self.norm = norm_layer(embed_dim)
self.avg_pool = nn.Adapti... | #x -> (B, H, W, C)-> (B, C, H, W)
x = x.permute(0,3,1,2)
B, C, _, _ = x.size()
x_channel = self.channel(self.avg_pool(x).view(B, C)).view(B, C, 1, 1) * x
x_spatial = self.spatial(x_channel)
if self.skip_connect:
x = x + x_spatial
else:
... | #x -> (B, H, W, C)-> (B, C, H, W)
x = x.permute(0,3,1,2)
B, C, _, _ = x.size()
x_channel = self.channel(self.avg_pool(x).view(B, C)).view(B, C, 1, 1) * x
x_spatial = self.spatial(x_channel)
if self.skip_connect:
x = x + x_spatial
else:
... | 56 | 401 | 221 | 622 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,668 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/image_encoder.py | 280,281 | 241,299 | forward | Attention | 281,299 | 281,299 | class Attention(nn.Module):
"""Multi-head Attention block with relative position embeddings."""
def __init__(
self,
dim: int,
num_heads: int = 8,
qkv_bias: bool = True,
use_rel_pos: bool = False,
rel_pos_zero_init: bool = True,
input_size: Optional[Tuple[... | class Attention(nn.Module):
"""Multi-head Attention block with relative position embeddings."""
def __init__(
self,
dim: int,
num_heads: int = 8,
qkv_bias: bool = True,
use_rel_pos: bool = False,
rel_pos_zero_init: bool = True,
input_size: Optional[Tuple[... | B, H, W, _ = x.shape
# qkv with shape (3, B, nHead, H * W, C)
qkv = self.qkv(x).reshape(B, H * W, 3, self.num_heads, -1).permute(2, 0, 3, 1, 4)
# q, k, v with shape (B * nHead, H * W, C)
q, k, v = qkv.reshape(3, B * self.num_heads, H * W, -1).unbind(0)
attn = (q * self.s... | B, H, W, _ = x.shape
# qkv with shape (3, B, nHead, H * W, C)
qkv = self.qkv(x).reshape(B, H * W, 3, self.num_heads, -1).permute(2, 0, 3, 1, 4)
# q, k, v with shape (B * nHead, H * W, C)
q, k, v = qkv.reshape(3, B * self.num_heads, H * W, -1).unbind(0)
attn = (q * self.s... | 99 | 516 | 341 | 857 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,669 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/image_encoder.py | 217,218 | 165,241 | forward | Block | 218,241 | 218,241 | class Block(nn.Module):
"""Transformer blocks with support of window attention and residual propagation blocks"""
def __init__(
self,
dim: int,
num_heads: int,
mlp_ratio: float = 4.0,
qkv_bias: bool = True,
norm_layer: Type[nn.Module] = nn.LayerNorm,
act_... | class Block(nn.Module):
"""Transformer blocks with support of window attention and residual propagation blocks"""
def __init__(
self,
dim: int,
num_heads: int,
mlp_ratio: float = 4.0,
qkv_bias: bool = True,
norm_layer: Type[nn.Module] = nn.LayerNorm,
act_... | shortcut = x
x = self.norm1(x)
# Window partition
if self.window_size > 0:
H, W = x.shape[1], x.shape[2]
x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x)
# Reverse window partition
if self.window_size > 0:
x =... | shortcut = x
x = self.norm1(x)
# Window partition
if self.window_size > 0:
H, W = x.shape[1], x.shape[2]
x, pad_hw = window_partition(x, self.window_size)
x = self.attn(x)
# Reverse window partition
if self.window_size > 0:
x =... | 66 | 652 | 233 | 885 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,670 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/image_encoder.py | 151,152 | 59,165 | forward | ImageEncoderViT | 152,165 | 152,165 | class ImageEncoderViT(nn.Module):
def __init__(
self,
img_size: int = 1024,
patch_size: int = 16,
in_chans: int = 3,
embed_dim: int = 768,
depth: int = 12,
num_heads: int = 12,
mlp_ratio: float = 4.0,
out_chans: int = 256,
qkv_bias: boo... | class ImageEncoderViT(nn.Module):
def __init__(
self,
img_size: int = 1024,
patch_size: int = 16,
in_chans: int = 3,
embed_dim: int = 768,
depth: int = 12,
num_heads: int = 12,
mlp_ratio: float = 4.0,
out_chans: int = 256,
qkv_bias: boo... | x = self.patch_embed(x)
if self.pos_embed is not None:
x = x + self.pos_embed
for blk in self.blocks:
x = blk(x)
x = self.neck(x.permute(0, 3, 1, 2))
return x
| x = self.patch_embed(x)
if self.pos_embed is not None:
x = x + self.pos_embed
for blk in self.blocks:
x = blk(x)
x = self.neck(x.permute(0, 3, 1, 2))
return x
| 28 | 1,057 | 103 | 1,160 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,671 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/image_encoder.py | 451,452 | 424,456 | forward | PatchEmbed | 452,456 | 452,456 | class PatchEmbed(nn.Module):
"""
Image to Patch Embedding.
"""
def __init__(
self,
kernel_size: Tuple[int, int] = (16, 16),
stride: Tuple[int, int] = (16, 16),
padding: Tuple[int, int] = (0, 0),
in_chans: int = 3,
embed_dim: int = 768,
) -> None:
... | class PatchEmbed(nn.Module):
"""
Image to Patch Embedding.
"""
def __init__(
self,
kernel_size: Tuple[int, int] = (16, 16),
stride: Tuple[int, int] = (16, 16),
padding: Tuple[int, int] = (0, 0),
in_chans: int = 3,
embed_dim: int = 768,
) -> None:
... | x = self.proj(x)
# B C H W -> B H W C
x = x.permute(0, 2, 3, 1)
return x
| x = self.proj(x)
# B C H W -> B H W C
x = x.permute(0, 2, 3, 1)
return x
| 21 | 308 | 52 | 360 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, Type
from .common... |
50,672 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/mask_decoder.py | 175,176 | 158,187 | forward | MLP | 176,187 | 176,187 | class MLP(nn.Module):
def __init__(
self,
input_dim: int,
hidden_dim: int,
output_dim: int,
num_layers: int,
sigmoid_output: bool = False,
) -> None:
super().__init__()
self.num_layers = num_layers
h = [hidden_dim] * (num_layers - 1)
... | class MLP(nn.Module):
def __init__(
self,
input_dim: int,
hidden_dim: int,
output_dim: int,
num_layers: int,
sigmoid_output: bool = False,
) -> None:
super().__init__()
self.num_layers = num_layers
h = [hidden_dim] * (num_layers - 1)
... | for i, layer in enumerate(self.layers):
# x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
# x = self.relu(layer(x)) if i < self.num_layers - 1 else layer(x) #源码
if i < self.num_layers - 1:
x = F.relu(layer(x))
else:
x ... | for i, layer in enumerate(self.layers):
# x = F.relu(layer(x)) if i < self.num_layers - 1 else layer(x)
# x = self.relu(layer(x)) if i < self.num_layers - 1 else layer(x) #源码
if i < self.num_layers - 1:
x = F.relu(layer(x))
else:
x ... | 50 | 207 | 155 | 362 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... |
50,673 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/mask_decoder.py | 113,120 | 16,158 | predict_masks | MaskDecoder | 121,158 | 120,158 | class MaskDecoder(nn.Module):
def __init__(
self,
*,
transformer_dim: int,
transformer: nn.Module,
num_multimask_outputs: int = 3,
activation: Type[nn.Module] = nn.GELU,
iou_head_depth: int = 3,
iou_head_hidden_dim: int = 256,
) -> None:
""... | class MaskDecoder(nn.Module):
def __init__(
self,
*,
transformer_dim: int,
transformer: nn.Module,
num_multimask_outputs: int = 3,
activation: Type[nn.Module] = nn.GELU,
iou_head_depth: int = 3,
iou_head_hidden_dim: int = 256,
) -> None:
""... | # Concatenate output tokens
output_tokens = torch.cat([self.iou_token.weight, self.mask_tokens.weight], dim=0) #iou_token:[1,256] mask_tokens:[4,256]
output_tokens = output_tokens.unsqueeze(0).expand(sparse_prompt_embeddings.size(0), -1, -1)
tokens = torch.cat((output_tokens, sparse_p... | """Predicts masks. See 'forward' for more details."""
# Concatenate output tokens
output_tokens = torch.cat([self.iou_token.weight, self.mask_tokens.weight], dim=0) #iou_token:[1,256] mask_tokens:[4,256]
output_tokens = output_tokens.unsqueeze(0).expand(sparse_prompt_embeddings.size(0... | 158 | 1,281 | 685 | 1,966 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import List, Tuple, Type
from .common... |
50,674 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/prompt_encoder.py | 206,207 | 182,229 | forward | PositionEmbeddingRandom | 208,220 | 207,220 | class PositionEmbeddingRandom(nn.Module):
"""
Positional encoding using random spatial frequencies.
"""
def __init__(self, num_pos_feats: int = 64, scale: Optional[float] = None) -> None:
super().__init__()
if scale is None or scale <= 0.0:
scale = 1.0
self.register_... | class PositionEmbeddingRandom(nn.Module):
"""
Positional encoding using random spatial frequencies.
"""
def __init__(self, num_pos_feats: int = 64, scale: Optional[float] = None) -> None:
super().__init__()
if scale is None or scale <= 0.0:
scale = 1.0
self.register_... | h, w = size
device: Any = self.positional_encoding_gaussian_matrix.device
grid = torch.ones((h, w), device=device, dtype=torch.float32)
y_embed = grid.cumsum(dim=0) - 0.5
x_embed = grid.cumsum(dim=1) - 0.5
y_embed = y_embed / h
x_embed = x_embed / w
pe =... | """Generate positional encoding for a grid of the specified size."""
h, w = size
device: Any = self.positional_encoding_gaussian_matrix.device
grid = torch.ones((h, w), device=device, dtype=torch.float32)
y_embed = grid.cumsum(dim=0) - 0.5
x_embed = grid.cumsum(dim=1) - ... | 49 | 543 | 184 | 727 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch import nn
from typing import Any, Optional, Tuple, Type
from .common import L... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch import nn
from typing import Any, Optional, Tuple, Type
from .common import L... |
50,676 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/transformer.py | 218,219 | 185,245 | forward | Attention | 219,245 | 219,245 | class Attention(nn.Module):
"""
An attention layer that allows for downscaling the size of the embedding
after projection to queries, keys, and values.
"""
def __init__(
self,
embedding_dim: int,
num_heads: int,
downsample_rate: int = 1,
) -> None:
super(... | class Attention(nn.Module):
"""
An attention layer that allows for downscaling the size of the embedding
after projection to queries, keys, and values.
"""
def __init__(
self,
embedding_dim: int,
num_heads: int,
downsample_rate: int = 1,
) -> None:
super(... | # Input projections
q = self.q_proj(q.to(self.q_proj.weight.dtype)) #todo
k = self.k_proj(k.to(self.k_proj.weight.dtype)) #todo
v = self.v_proj(v.to(self.v_proj.weight.dtype)) #todo
# q = self.q_proj(q)
# k = self.k_proj(k)
# v = self.v_proj(v)
# Separat... | # Input projections
q = self.q_proj(q.to(self.q_proj.weight.dtype)) #todo
k = self.k_proj(k.to(self.k_proj.weight.dtype)) #todo
v = self.v_proj(v.to(self.v_proj.weight.dtype)) #todo
# q = self.q_proj(q)
# k = self.k_proj(k)
# v = self.v_proj(v)
# Separat... | 92 | 494 | 373 | 867 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,677 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/transformer.py | 151,154 | 109,185 | forward | TwoWayAttentionBlock | 154,185 | 154,185 | class TwoWayAttentionBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
num_heads: int,
mlp_dim: int = 2048,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
skip_first_layer_pe: bool = False,
) -> None:
"""
... | class TwoWayAttentionBlock(nn.Module):
def __init__(
self,
embedding_dim: int,
num_heads: int,
mlp_dim: int = 2048,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
skip_first_layer_pe: bool = False,
) -> None:
"""
... | # Self attention block
if self.skip_first_layer_pe:
queries = self.self_attn(q=queries, k=queries, v=queries)
else:
q = queries + query_pe
attn_out = self.self_attn(q=q, k=q, v=queries)
queries = queries + attn_out
queries = self.norm1(quer... | # Self attention block
if self.skip_first_layer_pe:
queries = self.self_attn(q=queries, k=queries, v=queries)
else:
q = queries + query_pe
attn_out = self.self_attn(q=q, k=q, v=queries)
queries = queries + attn_out
queries = self.norm1(quer... | 111 | 553 | 361 | 914 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,678 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/modeling/transformer.py | 62,68 | 16,109 | forward | TwoWayTransformer | 81,109 | 68,109 | class TwoWayTransformer(nn.Module):
def __init__(
self,
depth: int,
embedding_dim: int,
num_heads: int,
mlp_dim: int,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
) -> None:
"""
A transformer decoder that atten... | class TwoWayTransformer(nn.Module):
def __init__(
self,
depth: int,
embedding_dim: int,
num_heads: int,
mlp_dim: int,
activation: Type[nn.Module] = nn.ReLU,
attention_downsample_rate: int = 2,
) -> None:
"""
A transformer decoder that atten... | # BxCxHxW -> BxHWxC == B x N_image_tokens x C
bs, c, h, w = image_embedding.shape
image_embedding = image_embedding.flatten(2).permute(0, 2, 1)
image_pe = image_pe.flatten(2).permute(0, 2, 1)
# Prepare queries
queries = point_embedding
keys = image_embedding
... | """
Args:
image_embedding (torch.Tensor): image to attend to. Should be shape
B x embedding_dim x h x w for any h and w.
image_pe (torch.Tensor): the positional encoding to add to the image. Must
have the same shape as image_embedding.
point_embeddin... | 93 | 675 | 320 | 995 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... |
50,681 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/utils/transforms.py | 66,69 | 16,103 | apply_coords_torch | ResizeLongestSide | 73,83 | 69,83 | class ResizeLongestSide:
"""
Resizes images to the longest side 'target_length', as well as provides
methods for resizing coordinates and boxes. Provides methods for
transforming both numpy array and batched torch tensors.
"""
def __init__(self, target_length: int) -> None:
self.target_... | class ResizeLongestSide:
"""
Resizes images to the longest side 'target_length', as well as provides
methods for resizing coordinates and boxes. Provides methods for
transforming both numpy array and batched torch tensors.
"""
def __init__(self, target_length: int) -> None:
self.target_... | old_h, old_w = original_size
new_h, new_w = self.get_preprocess_shape(
original_size[0], original_size[1], self.target_length
)
coords = deepcopy(coords).to(torch.float)
coords[..., 0] = coords[..., 0] * (new_w / old_w)
coords[..., 1] = coords[..., 1] * (new_... | """
Expects a torch tensor with length 2 in the last dimension. Requires the
original image size in (H, W) format.
"""
old_h, old_w = original_size
new_h, new_w = self.get_preprocess_shape(
original_size[0], original_size[1], self.target_length
)
... | 35 | 1,062 | 147 | 1,209 | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import numpy as np
import torch
from torch.nn import functional as F
from torchvision.transforms.functional import resize,... |
50,682 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/segment_any/segment_anything_med2d/utils/transforms_med2d.py | 13,14 | 11,20 | apply_image | Med2dTransforms | 14,17 | 14,17 | class Med2dTransforms(ResizeLongestSide):
def apply_image(self, image: np.ndarray):
FILL_FUNC_BODY @staticmethod
def get_preprocess_shape(oldh: int, oldw: int, long_side_length: int) -> Tuple[int, int]:
return (long_side_length, long_side_length)
| class Med2dTransforms(ResizeLongestSide):
def apply_image(self, image: np.ndarray):
FILL_FUNC_BODY @staticmethod
def get_preprocess_shape(oldh: int, oldw: int, long_side_length: int) -> Tuple[int, int]:
return (long_side_length, long_side_length)
| image = cv2.resize(image, (256, 256), interpolation=cv2.INTER_NEAREST)
return image
| image = cv2.resize(image, (256, 256), interpolation=cv2.INTER_NEAREST)
return image
| 8 | 99 | 42 | 141 | # -*- coding: utf-8 -*-
# @Author : LG
from .transforms import ResizeLongestSide
import numpy as np
from typing import Tuple
import cv2
class Med2dTransforms(ResizeLongestSide):
def apply_image(self, image: np.ndarray):
FILL_FUNC_BODY @staticmethod
def get_preprocess_shape(oldh: int, oldw: int, long_si... | # -*- coding: utf-8 -*-
# @Author : LG
from .transforms import ResizeLongestSide
import numpy as np
from typing import Tuple
import cv2
class Med2dTransforms(ResizeLongestSide):
def apply_image(self, image: np.ndarray):
FILL_FUNC_BODY @staticmethod
def get_preprocess_shape(oldh: int, oldw: int, long_si... |
50,685 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/ui/about_dialog.py | 15,16 | 14,78 | setupUi | Ui_Dialog | 16,70 | 16,70 | class Ui_Dialog(object):
def setupUi(self, Dialog):
FILL_FUNC_BODY def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "about"))
self.label.setText(_translate("Dialog", "About"))
self.label_2.setText(_translate... | class Ui_Dialog(object):
def setupUi(self, Dialog):
FILL_FUNC_BODY def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "about"))
self.label.setText(_translate("Dialog", "About"))
self.label_2.setText(_translate... | Dialog.setObjectName("Dialog")
Dialog.resize(550, 280)
Dialog.setMinimumSize(QtCore.QSize(550, 280))
Dialog.setMaximumSize(QtCore.QSize(550, 280))
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.widget =... | Dialog.setObjectName("Dialog")
Dialog.resize(550, 280)
Dialog.setMinimumSize(QtCore.QSize(550, 280))
Dialog.setMaximumSize(QtCore.QSize(550, 280))
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setObjectName("verticalLayout")
self.widget =... | 94 | 175 | 982 | 1,157 | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/about_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file u... | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/about_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file u... |
50,686 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/ui/anno_dock.py | 15,16 | 14,72 | setupUi | Ui_Form | 16,68 | 16,68 | class Ui_Form(object):
def setupUi(self, Form):
FILL_FUNC_BODY def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.checkBox_visible.setText(_translate("Form", "Visible"))
| class Ui_Form(object):
def setupUi(self, Form):
FILL_FUNC_BODY def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.checkBox_visible.setText(_translate("Form", "Visible"))
| Form.setObjectName("Form")
Form.resize(339, 302)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setContentsMargins(2, 2, 2, 2)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName("verticalLayout")
self.widget = QtWidgets.QWid... | Form.setObjectName("Form")
Form.resize(339, 302)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setContentsMargins(2, 2, 2, 2)
self.verticalLayout.setSpacing(0)
self.verticalLayout.setObjectName("verticalLayout")
self.widget = QtWidgets.QWid... | 94 | 88 | 1,061 | 1,149 | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/anno_dock.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unle... | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/anno_dock.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unle... |
50,687 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/ui/auto_segment.py | 92,93 | 14,104 | retranslateUi | Ui_Dialog | 93,104 | 93,104 | class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(1000, 680)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(12)
Dialog.setFont(font)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
... | class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(1000, 680)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(12)
Dialog.setFont(font)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
... | _translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Auto segment"))
self.lineEdit_image_dir.setPlaceholderText(_translate("Dialog", "Image dir"))
self.pushButton_image_dir.setText(_translate("Dialog", "image root"))
self.lineEdit_label_dir.s... | _translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Auto segment"))
self.lineEdit_image_dir.setPlaceholderText(_translate("Dialog", "Image dir"))
self.pushButton_image_dir.setText(_translate("Dialog", "image root"))
self.lineEdit_label_dir.s... | 46 | 1,416 | 266 | 1,682 | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/auto_segment.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file u... | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/auto_segment.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file u... |
50,689 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/ui/category_dock.py | 15,16 | 14,66 | setupUi | Ui_Form | 16,52 | 16,52 | class Ui_Form(object):
def setupUi(self, Form):
FILL_FUNC_BODY def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton_group_mode.setStatusTip(_translate("Form", "Group mode"))
self.pushButton_gr... | class Ui_Form(object):
def setupUi(self, Form):
FILL_FUNC_BODY def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton_group_mode.setStatusTip(_translate("Form", "Group mode"))
self.pushButton_gr... | Form.setObjectName("Form")
Form.resize(294, 462)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setObjectName("verticalLayout")
self.listWidget = QtWidgets.QListWidget(Form)
self.listWidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelectio... | Form.setObjectName("Form")
Form.resize(294, 462)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setObjectName("verticalLayout")
self.listWidget = QtWidgets.QListWidget(Form)
self.listWidget.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelectio... | 56 | 316 | 751 | 1,067 | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/home/super/PycharmProjects/ISAT_with_segment_anything/ui/category_dock.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unle... | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/home/super/PycharmProjects/ISAT_with_segment_anything/ui/category_dock.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unle... |
50,690 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/ui/file_dock.py | 15,16 | 14,86 | setupUi | Ui_Form | 16,74 | 16,74 | class Ui_Form(object):
def setupUi(self, Form):
FILL_FUNC_BODY def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label_prev_state.setStatusTip(_translate("Form", "Prev image SAM state"))
self.label_pr... | class Ui_Form(object):
def setupUi(self, Form):
FILL_FUNC_BODY def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label_prev_state.setStatusTip(_translate("Form", "Prev image SAM state"))
self.label_pr... | Form.setObjectName("Form")
Form.resize(264, 341)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setContentsMargins(9, 9, 9, 9)
self.verticalLayout.setSpacing(6)
self.verticalLayout.setObjectName("verticalLayout")
self.listWidget = QtWidgets.... | Form.setObjectName("Form")
Form.resize(264, 341)
self.verticalLayout = QtWidgets.QVBoxLayout(Form)
self.verticalLayout.setContentsMargins(9, 9, 9, 9)
self.verticalLayout.setSpacing(6)
self.verticalLayout.setObjectName("verticalLayout")
self.listWidget = QtWidgets.... | 105 | 298 | 1,154 | 1,452 | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/file_dock.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unle... | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/file_dock.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unle... |
50,691 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/ui/info_dock.py | 86,87 | 14,94 | retranslateUi | Ui_Form | 87,94 | 87,94 | class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(347, 156)
Form.setMinimumSize(QtCore.QSize(0, 100))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(12)
Form.setFont(font)
self.verticalLayo... | class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(347, 156)
Form.setMinimumSize(QtCore.QSize(0, 100))
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(12)
Form.setFont(font)
self.verticalLayo... | _translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "width :"))
self.label_2.setText(_translate("Form", "height:"))
self.label_3.setText(_translate("Form", "depth :"))
self.label_5.setText(_t... | _translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.label.setText(_translate("Form", "width :"))
self.label_2.setText(_translate("Form", "height:"))
self.label_3.setText(_translate("Form", "depth :"))
self.label_5.setText(_t... | 21 | 1,271 | 130 | 1,401 | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/home/super/PycharmProjects/ISAT/ui/info_dock.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are d... | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/home/super/PycharmProjects/ISAT/ui/info_dock.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are d... |
50,692 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/ui/model_manager_dialog.py | 15,16 | 14,98 | setupUi | Ui_Dialog | 16,83 | 16,83 | class Ui_Dialog(object):
def setupUi(self, Dialog):
FILL_FUNC_BODY def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Model Manage"))
self.checkBox_use_bfloat16.setText(_translate("Dialog", "use bfloat16"))
s... | class Ui_Dialog(object):
def setupUi(self, Dialog):
FILL_FUNC_BODY def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Model Manage"))
self.checkBox_use_bfloat16.setText(_translate("Dialog", "use bfloat16"))
s... | Dialog.setObjectName("Dialog")
Dialog.resize(800, 360)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(12)
Dialog.setFont(font)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setContentsMargins(9, 9, 9, 9)
... | Dialog.setObjectName("Dialog")
Dialog.resize(800, 360)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(12)
Dialog.setFont(font)
self.verticalLayout = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout.setContentsMargins(9, 9, 9, 9)
... | 119 | 282 | 1,258 | 1,540 | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/model_manager_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit thi... | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '/mnt/disk2/PycharmProjects/ISAT_with_segment_anything/ISAT/ui/model_manager_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit thi... |
50,693 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/ui/setting_dialog.py | 15,16 | 14,112 | setupUi | Ui_Dialog | 16,102 | 16,102 | class Ui_Dialog(object):
def setupUi(self, Dialog):
FILL_FUNC_BODY def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Setting"))
self.label.setText(_translate("Dialog", "Label"))
self.add_button.setText(_tran... | class Ui_Dialog(object):
def setupUi(self, Dialog):
FILL_FUNC_BODY def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Setting"))
self.label.setText(_translate("Dialog", "Label"))
self.add_button.setText(_tran... | Dialog.setObjectName("Dialog")
Dialog.resize(607, 369)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(12)
Dialog.setFont(font)
self.verticalLayout_2 = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout_2.setObjectName("verticalLayo... | Dialog.setObjectName("Dialog")
Dialog.resize(607, 369)
font = QtGui.QFont()
font.setFamily("Times New Roman")
font.setPointSize(12)
Dialog.setFont(font)
self.verticalLayout_2 = QtWidgets.QVBoxLayout(Dialog)
self.verticalLayout_2.setObjectName("verticalLayo... | 159 | 183 | 1,712 | 1,895 | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'setting_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCor... | # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'setting_dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.7
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCor... |
50,696 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/category_choice_dialog.py | 63,64 | 8,103 | get_category | CategoryChoiceDialog | 64,69 | 64,69 | class CategoryChoiceDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow, scene):
super(CategoryChoiceDialog, self).__init__(parent)
self.setupUi(self)
self.mainwindow = mainwindow
self.scene = scene
self.lineEdit_group.setValidator(QtGui.QIntValidato... | class CategoryChoiceDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow, scene):
super(CategoryChoiceDialog, self).__init__(parent)
self.setupUi(self)
self.mainwindow = mainwindow
self.scene = scene
self.lineEdit_group.setValidator(QtGui.QIntValidato... | widget = self.listWidget.itemWidget(item)
label_category = widget.findChild(QtWidgets.QLabel, 'label_category')
self.lineEdit_category.setText(label_category.text())
self.lineEdit_category.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
| widget = self.listWidget.itemWidget(item)
label_category = widget.findChild(QtWidgets.QLabel, 'label_category')
self.lineEdit_category.setText(label_category.text())
self.lineEdit_category.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)
| 9 | 1,055 | 86 | 1,141 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtGui, QtCore
from ISAT.ui.category_choice import Ui_Dialog
class CategoryChoiceDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow, scene):
super(CategoryChoiceDialog, self).__init__(parent)
self.setupU... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtGui, QtCore
from ISAT.ui.category_choice import Ui_Dialog
class CategoryChoiceDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow, scene):
super(CategoryChoiceDialog, self).__init__(parent)
self.setupU... |
50,697 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/category_dock_widget.py | 61,62 | 8,99 | item_choice | CategoriesDockWidget | 62,68 | 62,68 | class CategoriesDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(CategoriesDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = mainwindow
self.listWidget.itemClicked.connect(self.item_choice)
# 新增 手动/自动 group 选择
self.lineEdi... | class CategoriesDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(CategoriesDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = mainwindow
self.listWidget.itemClicked.connect(self.item_choice)
# 新增 手动/自动 group 选择
self.lineEdi... | for index in range(self.listWidget.count()):
item = self.listWidget.item(index)
widget = self.listWidget.itemWidget(item)
label_radio = widget.findChild(QtWidgets.QRadioButton, 'label_radio')
label_radio.setChecked(item==item_now)
| for index in range(self.listWidget.count()):
item = self.listWidget.item(index)
widget = self.listWidget.itemWidget(item)
label_radio = widget.findChild(QtWidgets.QRadioButton, 'label_radio')
label_radio.setChecked(item==item_now)
| 15 | 1,152 | 90 | 1,242 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtCore
from ISAT.ui.category_dock import Ui_Form
class CategoriesDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(CategoriesDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = m... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtCore
from ISAT.ui.category_dock import Ui_Form
class CategoriesDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(CategoriesDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = m... |
50,698 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/category_edit_dialog.py | 25,26 | 8,114 | load_cfg | CategoryEditDialog | 26,81 | 26,81 | class CategoryEditDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow, scene):
super(CategoryEditDialog, self).__init__(parent)
self.setupUi(self)
self.mainwindow = mainwindow
self.scene = scene
self.polygon = None
self.lineEdit_group.setVali... | class CategoryEditDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow, scene):
super(CategoryEditDialog, self).__init__(parent)
self.setupUi(self)
self.mainwindow = mainwindow
self.scene = scene
self.polygon = None
self.lineEdit_group.setVali... | self.listWidget.clear()
labels = self.mainwindow.cfg.get('label', [])
for label in labels:
name = label.get('name', 'UNKNOW')
color = label.get('color', '#000000')
# item = QtWidgets.QListWidgetItem()
# item.setText(name)
# item.setTe... | self.listWidget.clear()
labels = self.mainwindow.cfg.get('label', [])
for label in labels:
name = label.get('name', 'UNKNOW')
color = label.get('color', '#000000')
# item = QtWidgets.QListWidgetItem()
# item.setText(name)
# item.setTe... | 107 | 589 | 775 | 1,364 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtGui, QtCore
from ISAT.ui.category_choice import Ui_Dialog
class CategoryEditDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow, scene):
super(CategoryEditDialog, self).__init__(parent)
self.setupUi(se... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtGui, QtCore
from ISAT.ui.category_choice import Ui_Dialog
class CategoryEditDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow, scene):
super(CategoryEditDialog, self).__init__(parent)
self.setupUi(se... |
50,699 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/files_dock_widget.py | 37,38 | 9,61 | update_widget | FilesDockWidget | 38,54 | 38,54 | class FilesDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(FilesDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = mainwindow
self.listWidget.clicked.connect(self.listwidget_doubleclick)
self.lineEdit_jump.returnPressed.connect(sel... | class FilesDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(FilesDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = mainwindow
self.listWidget.clicked.connect(self.listwidget_doubleclick)
self.lineEdit_jump.returnPressed.connect(sel... | self.listWidget.clear()
if self.mainwindow.files_list is None:
return
for idx, file_path in enumerate(self.mainwindow.files_list):
_, file_name = os.path.split(file_path)
item = QtWidgets.QListWidgetItem()
item.setSizeHint(QtCore.QSize(200, 30))
... | self.listWidget.clear()
if self.mainwindow.files_list is None:
return
for idx, file_path in enumerate(self.mainwindow.files_list):
_, file_name = os.path.split(file_path)
item = QtWidgets.QListWidgetItem()
item.setSizeHint(QtCore.QSize(200, 30))
... | 34 | 437 | 219 | 656 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtCore, QtGui
from ISAT.ui.file_dock import Ui_Form
import os
class FilesDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(FilesDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow ... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtCore, QtGui
from ISAT.ui.file_dock import Ui_Form
import os
class FilesDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(FilesDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow ... |
50,700 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/info_dock_widget.py | 19,20 | 7,25 | update_widget | InfoDockWidget | 20,25 | 20,25 | class InfoDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(InfoDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = mainwindow
self.lineEdit_note.textChanged.connect(self.note_changed)
def note_changed(self):
if self.mainwindow.... | class InfoDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(InfoDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = mainwindow
self.lineEdit_note.textChanged.connect(self.note_changed)
def note_changed(self):
if self.mainwindow.... | if self.mainwindow.current_label is not None:
self.label_width.setText('{}'.format(self.mainwindow.current_label.width))
self.label_height.setText('{}'.format(self.mainwindow.current_label.height))
self.label_depth.setText('{}'.format(self.mainwindow.current_label.depth))
... | if self.mainwindow.current_label is not None:
self.label_width.setText('{}'.format(self.mainwindow.current_label.width))
self.label_height.setText('{}'.format(self.mainwindow.current_label.height))
self.label_depth.setText('{}'.format(self.mainwindow.current_label.depth))
... | 9 | 143 | 117 | 260 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtCore, QtGui
from ISAT.ui.info_dock import Ui_Form
class InfoDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(InfoDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = mainwindow
... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtCore, QtGui
from ISAT.ui.info_dock import Ui_Form
class InfoDockWidget(QtWidgets.QWidget, Ui_Form):
def __init__(self, mainwindow):
super(InfoDockWidget, self).__init__()
self.setupUi(self)
self.mainwindow = mainwindow
... |
50,701 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/polygon.py | 377,378 | 337,391 | redraw | Line | 378,391 | 378,391 | class Line(QtWidgets.QGraphicsPathItem):
def __init__(self):
super().__init__(parent=None)
self.line_width = 1
# self.hover_alpha = 150
# self.nohover_alpha = 80
self.points = []
self.vertexs = []
self.color = QtGui.QColor('#ff0000')
def addPoint(self, po... | class Line(QtWidgets.QGraphicsPathItem):
def __init__(self):
super().__init__(parent=None)
self.line_width = 1
# self.hover_alpha = 150
# self.nohover_alpha = 80
self.points = []
self.vertexs = []
self.color = QtGui.QColor('#ff0000')
def addPoint(self, po... | if len(self.points) < 1:
return
xs = [p.x() for p in self.points]
ys = [p.y() for p in self.points]
self.rxmin, self.rymin, self.rxmax, self.rymax = min(xs), min(ys), max(xs), max(ys)
line_path = QtGui.QPainterPath()
if self.points:
line_path.move... | if len(self.points) < 1:
return
xs = [p.x() for p in self.points]
ys = [p.y() for p in self.points]
self.rxmin, self.rymin, self.rxmax, self.rymax = min(xs), min(ys), max(xs), max(ys)
line_path = QtGui.QPainterPath()
if self.points:
line_path.move... | 40 | 383 | 172 | 555 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtCore, QtWidgets, QtGui
from ISAT.annotation import Object
import typing
from ISAT.configs import STATUSMode, CLICKMode, DRAWMode, CONTOURMode
class PromptPoint(QtWidgets.QGraphicsPathItem):
def __init__(self, pos, type=0):
super(PromptPoint, sel... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtCore, QtWidgets, QtGui
from ISAT.annotation import Object
import typing
from ISAT.configs import STATUSMode, CLICKMode, DRAWMode, CONTOURMode
class PromptPoint(QtWidgets.QGraphicsPathItem):
def __init__(self, pos, type=0):
super(PromptPoint, sel... |
50,702 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/polygon.py | 313,314 | 289,337 | itemChange | LineVertex | 314,337 | 314,337 | class LineVertex(QtWidgets.QGraphicsPathItem):
def __init__(self, polygon, color, nohover_size=2):
super(LineVertex, self).__init__()
self.polygon = polygon
self.color = color
self.color.setAlpha(255)
self.nohover_size = nohover_size
self.hover_size = self.nohover_siz... | class LineVertex(QtWidgets.QGraphicsPathItem):
def __init__(self, polygon, color, nohover_size=2):
super(LineVertex, self).__init__()
self.polygon = polygon
self.color = color
self.color.setAlpha(255)
self.nohover_size = nohover_size
self.hover_size = self.nohover_siz... | if change == QtWidgets.QGraphicsItem.GraphicsItemChange.ItemSelectedHasChanged:
self.scene().mainwindow.actionDelete.setEnabled(self.isSelected())
if self.isSelected():
selected_color = QtGui.QColor('#00A0FF')
self.setBrush(selected_color)
else... | if change == QtWidgets.QGraphicsItem.GraphicsItemChange.ItemSelectedHasChanged:
self.scene().mainwindow.actionDelete.setEnabled(self.isSelected())
if self.isSelected():
selected_color = QtGui.QColor('#00A0FF')
self.setBrush(selected_color)
else... | 50 | 454 | 311 | 765 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtCore, QtWidgets, QtGui
from ISAT.annotation import Object
import typing
from ISAT.configs import STATUSMode, CLICKMode, DRAWMode, CONTOURMode
class PromptPoint(QtWidgets.QGraphicsPathItem):
def __init__(self, pos, type=0):
super(PromptPoint, sel... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtCore, QtWidgets, QtGui
from ISAT.annotation import Object
import typing
from ISAT.configs import STATUSMode, CLICKMode, DRAWMode, CONTOURMode
class PromptPoint(QtWidgets.QGraphicsPathItem):
def __init__(self, pos, type=0):
super(PromptPoint, sel... |
50,704 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/polygon.py | 56,57 | 26,99 | itemChange | Vertex | 57,80 | 57,80 | class Vertex(QtWidgets.QGraphicsPathItem):
def __init__(self, polygon, color, nohover_size=2):
super(Vertex, self).__init__()
self.polygon = polygon
self.color = color
self.color.setAlpha(255)
self.nohover_size = nohover_size
self.hover_size = self.nohover_size + 2
... | class Vertex(QtWidgets.QGraphicsPathItem):
def __init__(self, polygon, color, nohover_size=2):
super(Vertex, self).__init__()
self.polygon = polygon
self.color = color
self.color.setAlpha(255)
self.nohover_size = nohover_size
self.hover_size = self.nohover_size + 2
... | if change == QtWidgets.QGraphicsItem.GraphicsItemChange.ItemSelectedHasChanged:
self.scene().mainwindow.actionDelete.setEnabled(self.isSelected())
if self.isSelected():
selected_color = QtGui.QColor('#00A0FF')
self.setBrush(selected_color)
else... | if change == QtWidgets.QGraphicsItem.GraphicsItemChange.ItemSelectedHasChanged:
self.scene().mainwindow.actionDelete.setEnabled(self.isSelected())
if self.isSelected():
selected_color = QtGui.QColor('#00A0FF')
self.setBrush(selected_color)
else... | 50 | 797 | 311 | 1,108 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtCore, QtWidgets, QtGui
from ISAT.annotation import Object
import typing
from ISAT.configs import STATUSMode, CLICKMode, DRAWMode, CONTOURMode
class PromptPoint(QtWidgets.QGraphicsPathItem):
def __init__(self, pos, type=0):
super(PromptPoint, sel... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtCore, QtWidgets, QtGui
from ISAT.annotation import Object
import typing
from ISAT.configs import STATUSMode, CLICKMode, DRAWMode, CONTOURMode
class PromptPoint(QtWidgets.QGraphicsPathItem):
def __init__(self, pos, type=0):
super(PromptPoint, sel... |
50,705 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/ISAT/widgets/setting_dialog.py | 85,86 | 10,126 | import_cfg | SettingDialog | 86,93 | 86,93 | class SettingDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow):
super(SettingDialog, self).__init__(parent)
self.mainwindow = mainwindow
self.setupUi(self)
self.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
self.init_connect()
def ge... | class SettingDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow):
super(SettingDialog, self).__init__(parent)
self.mainwindow = mainwindow
self.setupUi(self)
self.setWindowModality(QtCore.Qt.WindowModality.WindowModal)
self.init_connect()
def ge... | file, _ = QtWidgets.QFileDialog.getOpenFileName(self, filter='Yaml File(*.yaml)')
if file:
self.mainwindow.config_file = file
self.mainwindow.actionSetting.setStatusTip("Config yaml: {}".format(file))
self.mainwindow.reload_cfg()
self.load_cfg()
| file, _ = QtWidgets.QFileDialog.getOpenFileName(self, filter='Yaml File(*.yaml)')
if file:
self.mainwindow.config_file = file
self.mainwindow.actionSetting.setStatusTip("Config yaml: {}".format(file))
self.mainwindow.reload_cfg()
self.load_cfg()
| 16 | 1,346 | 101 | 1,447 | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtCore, QtGui
from ISAT.ui.setting_dialog import Ui_Dialog
from ISAT.configs import *
import os
class SettingDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow):
super(SettingDialog, self).__init__(parent)
... | # -*- coding: utf-8 -*-
# @Author : LG
from PyQt5 import QtWidgets, QtCore, QtGui
from ISAT.ui.setting_dialog import Ui_Dialog
from ISAT.configs import *
import os
class SettingDialog(QtWidgets.QDialog, Ui_Dialog):
def __init__(self, parent, mainwindow):
super(SettingDialog, self).__init__(parent)
... |
50,706 | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything | /home/hieuvd/dung_repo/raw/stars_03/yatengLG_ISAT_with_segment_anything/ISAT_with_segment_anything/setup.py | 18,19 | 1,84 | get_install_requires | 19,30 | 19,30 | # -*- coding: utf-8 -*-
# @Author : LG
import os
import codecs
from setuptools import setup, find_packages
def get_version():
try:
from ISAT.__init__ import __version__
return __version__
except:
FileExistsError('ISAT/__init__.py not exists.')
def get_install_requires():
FILL_FUNC... | # -*- coding: utf-8 -*-
# @Author : LG
import os
import codecs
from setuptools import setup, find_packages
def get_version():
try:
from ISAT.__init__ import __version__
return __version__
except:
FileExistsError('ISAT/__init__.py not exists.')
def get_install_requires():
FILL_FUNC... | requirements_file = 'requirements.txt'
requirements_list = []
if os.path.exists(requirements_file):
with open(requirements_file) as f:
lines = f.readlines()
for line in lines:
line = line.rstrip('\n')
if line != '':
requirem... | requirements_file = 'requirements.txt'
requirements_list = []
if os.path.exists(requirements_file):
with open(requirements_file) as f:
lines = f.readlines()
for line in lines:
line = line.rstrip('\n')
if line != '':
requirem... | 29 | 695 | 110 | 805 | # -*- coding: utf-8 -*-
# @Author : LG
import os
import codecs
from setuptools import setup, find_packages
def get_version():
try:
from ISAT.__init__ import __version__
return __version__
except:
FileExistsError('ISAT/__init__.py not exists.')
def get_install_requires():
FILL_FUNC... | # -*- coding: utf-8 -*-
# @Author : LG
import os
import codecs
from setuptools import setup, find_packages
def get_version():
try:
from ISAT.__init__ import __version__
return __version__
except:
FileExistsError('ISAT/__init__.py not exists.')
def get_install_requires():
FILL_FUNC... | |
50,707 | /home/hieuvd/dung_repo/raw/stars_03/yunemse48_403bypasser/403bypasser | /home/hieuvd/dung_repo/raw/stars_03/yunemse48_403bypasser/403bypasser/403bypasser.py | 49,50 | 31,95 | checkURL | Arguments | 50,73 | 50,73 | class Arguments():
def __init__(self, url, urllist, dir, dirlist):
self.url = url
self.urllist = urllist
self.dir = dir
self.dirlist = dirlist
self.urls = []
self.dirs = []
self.checkURL()
self.checkDir()
def return_urls(self):
... | class Arguments():
def __init__(self, url, urllist, dir, dirlist):
self.url = url
self.urllist = urllist
self.dir = dir
self.dirlist = dirlist
self.urls = []
self.dirs = []
self.checkURL()
self.checkDir()
def return_urls(self):
... | if self.url:
if not validators.url(self.url):
print("You must specify a valid URL for -u (--url) argument! Exitting...\n")
sys.exit
if self.url.endswith("/"):
self.url = self.url.rstrip("/")
self.urls.a... | if self.url:
if not validators.url(self.url):
print("You must specify a valid URL for -u (--url) argument! Exitting...\n")
sys.exit
if self.url.endswith("/"):
self.url = self.url.rstrip("/")
self.urls.a... | 66 | 351 | 252 | 603 | import requests, sys, argparse, validators, os, tldextract
from colorama import init, Fore, Style
from pyfiglet import Figlet
# INITIALISE COLORAMA
init()
# DISPLAY BANNER -- START
custom_fig = Figlet(font='slant')
print(Fore.BLUE + Style.BRIGHT + custom_fig.renderText('-------------') + Style.RESET_ALL)
print(Fore.B... | import requests, sys, argparse, validators, os, tldextract
from colorama import init, Fore, Style
from pyfiglet import Figlet
# INITIALISE COLORAMA
init()
# DISPLAY BANNER -- START
custom_fig = Figlet(font='slant')
print(Fore.BLUE + Style.BRIGHT + custom_fig.renderText('-------------') + Style.RESET_ALL)
print(Fore.B... |
50,708 | /home/hieuvd/dung_repo/raw/stars_03/yunemse48_403bypasser/403bypasser | /home/hieuvd/dung_repo/raw/stars_03/yunemse48_403bypasser/403bypasser/403bypasser.py | 105,106 | 95,146 | createNewPaths | PathRepository | 106,125 | 106,125 | class PathRepository():
def __init__(self, path):
self.path = path
self.newPaths = []
self.newHeaders = []
self.rewriteHeaders = []
self.createNewPaths()
self.createNewHeaders()
def createNewPaths(self):
FILL_FUNC_BODY def createNewHeaders(self):
... | class PathRepository():
def __init__(self, path):
self.path = path
self.newPaths = []
self.newHeaders = []
self.rewriteHeaders = []
self.createNewPaths()
self.createNewHeaders()
def createNewPaths(self):
FILL_FUNC_BODY def createNewHeaders(self):
... | self.newPaths.append(self.path)
pairs = [["/", "//"], ["/.", "/./"]]
leadings = ["/%2e"]
trailings = ["/", "..;/", "/..;/", "%20", "%09", "%00",
".json", ".css", ".html", "?", "??", "???",
"?testparam", "#", "#test", "/... | self.newPaths.append(self.path)
pairs = [["/", "//"], ["/.", "/./"]]
leadings = ["/%2e"]
trailings = ["/", "..;/", "/..;/", "%20", "%09", "%00",
".json", ".css", ".html", "?", "??", "???",
"?testparam", "#", "#test", "/... | 51 | 454 | 221 | 675 | import requests, sys, argparse, validators, os, tldextract
from colorama import init, Fore, Style
from pyfiglet import Figlet
# INITIALISE COLORAMA
init()
# DISPLAY BANNER -- START
custom_fig = Figlet(font='slant')
print(Fore.BLUE + Style.BRIGHT + custom_fig.renderText('-------------') + Style.RESET_ALL)
print(Fore.B... | import requests, sys, argparse, validators, os, tldextract
from colorama import init, Fore, Style
from pyfiglet import Figlet
# INITIALISE COLORAMA
init()
# DISPLAY BANNER -- START
custom_fig = Figlet(font='slant')
print(Fore.BLUE + Style.BRIGHT + custom_fig.renderText('-------------') + Style.RESET_ALL)
print(Fore.B... |
50,709 | /home/hieuvd/dung_repo/raw/stars_03/yunemse48_403bypasser/403bypasser | /home/hieuvd/dung_repo/raw/stars_03/yunemse48_403bypasser/403bypasser/403bypasser.py | 264,265 | 259,276 | initialise | Program | 265,276 | 265,276 | class Program():
def __init__(self, urllist, dirlist):
self.urllist = urllist
self.dirlist = dirlist
def initialise(self):
FILL_FUNC_BODY | class Program():
def __init__(self, urllist, dirlist):
self.urllist = urllist
self.dirlist = dirlist
def initialise(self):
FILL_FUNC_BODY | for u in self.urllist:
for d in self.dirlist:
if d != "/":
dir_objname = d.lstrip("/")
else:
dir_objname = "_rootPath"
locals()[dir_objname] = PathRepository(d)
domain_name = tldextract.extract(u)... | for u in self.urllist:
for d in self.dirlist:
if d != "/":
dir_objname = d.lstrip("/")
else:
dir_objname = "_rootPath"
locals()[dir_objname] = PathRepository(d)
domain_name = tldextract.extract(u)... | 31 | 59 | 140 | 199 | import requests, sys, argparse, validators, os, tldextract
from colorama import init, Fore, Style
from pyfiglet import Figlet
# INITIALISE COLORAMA
init()
# DISPLAY BANNER -- START
custom_fig = Figlet(font='slant')
print(Fore.BLUE + Style.BRIGHT + custom_fig.renderText('-------------') + Style.RESET_ALL)
print(Fore.B... | import requests, sys, argparse, validators, os, tldextract
from colorama import init, Fore, Style
from pyfiglet import Figlet
# INITIALISE COLORAMA
init()
# DISPLAY BANNER -- START
custom_fig = Figlet(font='slant')
print(Fore.BLUE + Style.BRIGHT + custom_fig.renderText('-------------') + Style.RESET_ALL)
print(Fore.B... |
50,710 | /home/hieuvd/dung_repo/raw/stars_03/yunemse48_403bypasser/403bypasser | /home/hieuvd/dung_repo/raw/stars_03/yunemse48_403bypasser/403bypasser/403bypasser.py | 218,219 | 146,259 | manipulateHeaders | Query | 219,259 | 219,259 | class Query():
def __init__(self, url, dir, dirObject):
self.url = url
self.dir = dir # call pathrepo by this
self.dirObject = dirObject
self.domain = tldextract.extract(self.url).domain
def checkStatusCode(self, status_code):
if status_code == 200... | class Query():
def __init__(self, url, dir, dirObject):
self.url = url
self.dir = dir # call pathrepo by this
self.dirObject = dirObject
self.domain = tldextract.extract(self.url).domain
def checkStatusCode(self, status_code):
if status_code == 200... | results = []
line_width = 100
for header in self.dirObject.newHeaders:
r = requests.get(self.url + self.dir, headers=header)
colour = self.checkStatusCode(r.status_code)
reset = Style.RESET_ALL
target_address = "G... | results = []
line_width = 100
for header in self.dirObject.newHeaders:
r = requests.get(self.url + self.dir, headers=header)
colour = self.checkStatusCode(r.status_code)
reset = Style.RESET_ALL
target_address = "G... | 137 | 800 | 528 | 1,328 | import requests, sys, argparse, validators, os, tldextract
from colorama import init, Fore, Style
from pyfiglet import Figlet
# INITIALISE COLORAMA
init()
# DISPLAY BANNER -- START
custom_fig = Figlet(font='slant')
print(Fore.BLUE + Style.BRIGHT + custom_fig.renderText('-------------') + Style.RESET_ALL)
print(Fore.B... | import requests, sys, argparse, validators, os, tldextract
from colorama import init, Fore, Style
from pyfiglet import Figlet
# INITIALISE COLORAMA
init()
# DISPLAY BANNER -- START
custom_fig = Figlet(font='slant')
print(Fore.BLUE + Style.BRIGHT + custom_fig.renderText('-------------') + Style.RESET_ALL)
print(Fore.B... |
50,711 | /home/hieuvd/dung_repo/raw/stars_03/zhanlaoban_EDA_NLP_for_Chinese/EDA_NLP_for_Chinese | /home/hieuvd/dung_repo/raw/stars_03/zhanlaoban_EDA_NLP_for_Chinese/EDA_NLP_for_Chinese/code/augment.py | 35,36 | 1,55 | gen_eda | 36,53 | 36,53 | # @Author : zhany
# @Time : 2019/03/20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from eda import *
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("--input", required=True, type=str, help="原始数据的输入文件目录")
ap.add_argument("--output", required=False, type=str, help="增强数据后的输出文件目录")
ap.add_argument("--... | # @Author : zhany
# @Time : 2019/03/20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from eda import *
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("--input", required=True, type=str, help="原始数据的输入文件目录")
ap.add_argument("--output", required=False, type=str, help="增强数据后的输出文件目录")
ap.add_argument("--... |
writer = open(output_file, 'w')
lines = open(train_orig, 'r').readlines()
print("正在使用EDA生成增强语句...")
for i, line in enumerate(lines):
parts = line[:-1].split('\t') #使用[:-1]是把\n去掉了
label = parts[0]
sentence = parts[1]
aug_sentences = eda(sentence, alpha_sr=alpha, alpha... |
writer = open(output_file, 'w')
lines = open(train_orig, 'r').readlines()
print("正在使用EDA生成增强语句...")
for i, line in enumerate(lines):
parts = line[:-1].split('\t') #使用[:-1]是把\n去掉了
label = parts[0]
sentence = parts[1]
aug_sentences = eda(sentence, alpha_sr=alpha, alpha... | 46 | 416 | 229 | 645 | # @Author : zhany
# @Time : 2019/03/20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from eda import *
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("--input", required=True, type=str, help="原始数据的输入文件目录")
ap.add_argument("--output", required=False, type=str, help="增强数据后的输出文件目录")
ap.add_argument("--... | # @Author : zhany
# @Time : 2019/03/20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from eda import *
import argparse
ap = argparse.ArgumentParser()
ap.add_argument("--input", required=True, type=str, help="原始数据的输入文件目录")
ap.add_argument("--output", required=False, type=str, help="增强数据后的输出文件目录")
ap.add_argument("--... | |
50,712 | /home/hieuvd/dung_repo/raw/stars_03/zhanlaoban_EDA_NLP_for_Chinese/EDA_NLP_for_Chinese | /home/hieuvd/dung_repo/raw/stars_03/zhanlaoban_EDA_NLP_for_Chinese/EDA_NLP_for_Chinese/code/eda.py | 92,93 | 1,180 | swap_word | 93,108 | 93,108 | # @Author : zhany
# @Time : 2019/03/20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import jieba
import synonyms
import random
from random import shuffle
random.seed(2019)
#停用词列表,默认使用哈工大停用词表
f = open('stopwords/HIT_stop_words.txt')
stop_words = list()
for stop_word in f.readlines():
stop_words.append(stop_wor... | # @Author : zhany
# @Time : 2019/03/20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import jieba
import synonyms
import random
from random import shuffle
random.seed(2019)
#停用词列表,默认使用哈工大停用词表
f = open('stopwords/HIT_stop_words.txt')
stop_words = list()
for stop_word in f.readlines():
stop_words.append(stop_wor... | random_idx_1 = random.randint(0, len(new_words)-1)
random_idx_2 = random_idx_1
counter = 0
while random_idx_2 == random_idx_1:
random_idx_2 = random.randint(0, len(new_words)-1)
counter += 1
if counter > 3:
return new_words
new_words[random_idx_1], new_words[rando... | random_idx_1 = random.randint(0, len(new_words)-1)
random_idx_2 = random_idx_1
counter = 0
while random_idx_2 == random_idx_1:
random_idx_2 = random.randint(0, len(new_words)-1)
counter += 1
if counter > 3:
return new_words
new_words[random_idx_1], new_words[rando... | 40 | 1,533 | 191 | 1,724 | # @Author : zhany
# @Time : 2019/03/20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import jieba
import synonyms
import random
from random import shuffle
random.seed(2019)
#停用词列表,默认使用哈工大停用词表
f = open('stopwords/HIT_stop_words.txt')
stop_words = list()
for stop_word in f.readlines():
stop_words.append(stop_wor... | # @Author : zhany
# @Time : 2019/03/20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import jieba
import synonyms
import random
from random import shuffle
random.seed(2019)
#停用词列表,默认使用哈工大停用词表
f = open('stopwords/HIT_stop_words.txt')
stop_words = list()
for stop_word in f.readlines():
stop_words.append(stop_wor... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.