Metrics:
Total lines of code: 6400
Total lines skipped (#nosec): 0

blacklist: Consider possible security implications associated with the subprocess module.
Test ID: B404
Severity: LOW
Confidence: HIGH
CWE: CWE-78
File: /custom_nodes/comfyui_segment_anything/install.py
Line number: 3
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_imports.html#b404-import-subprocess
1	import sys
2	import os.path
3	import subprocess
4	
5	custom_nodes_path = os.path.dirname(os.path.abspath(__file__))
6	
7	def build_pip_install_cmds(args):
8	    if "python_embeded" in sys.executable or "python_embedded" in sys.executable:
subprocess_without_shell_equals_true: subprocess call - check for execution of untrusted input.
Test ID: B603
Severity: LOW
Confidence: HIGH
CWE: CWE-78
File: /custom_nodes/comfyui_segment_anything/install.py
Line number: 15
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b603_subprocess_without_shell_equals_true.html
11	        return [sys.executable, '-m', 'pip', 'install'] + args
12	
13	def ensure_package():
14	    cmds = build_pip_install_cmds(['-r', 'requirements.txt'])
15	    subprocess.run(cmds, cwd=custom_nodes_path)
16	
17	if __name__ == "__main__":
18	    ensure_package()
blacklist: Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Test ID: B311
Severity: LOW
Confidence: HIGH
CWE: CWE-330
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/datasets/transforms.py
Line number: 191
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b311-random
187	    def __call__(self, img: PIL.Image.Image, target: dict):
188	        init_boxes = len(target["boxes"])
189	        max_patience = 10
190	        for i in range(max_patience):
191	            w = random.randint(self.min_size, min(img.width, self.max_size))
192	            h = random.randint(self.min_size, min(img.height, self.max_size))
193	            region = T.RandomCrop.get_params(img, [h, w])
194	            result_img, result_target = crop(img, target, region)
blacklist: Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Test ID: B311
Severity: LOW
Confidence: HIGH
CWE: CWE-330
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/datasets/transforms.py
Line number: 192
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b311-random
188	        init_boxes = len(target["boxes"])
189	        max_patience = 10
190	        for i in range(max_patience):
191	            w = random.randint(self.min_size, min(img.width, self.max_size))
192	            h = random.randint(self.min_size, min(img.height, self.max_size))
193	            region = T.RandomCrop.get_params(img, [h, w])
194	            result_img, result_target = crop(img, target, region)
195	            if (
blacklist: Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Test ID: B311
Severity: LOW
Confidence: HIGH
CWE: CWE-330
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/datasets/transforms.py
Line number: 221
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b311-random
217	    def __init__(self, p=0.5):
218	        self.p = p
219	
220	    def __call__(self, img, target):
221	        if random.random() < self.p:
222	            return hflip(img, target)
223	        return img, target
224	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/datasets/transforms.py
Line number: 228
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
224	
225	
226	class RandomResize(object):
227	    def __init__(self, sizes, max_size=None):
228	        assert isinstance(sizes, (list, tuple))
229	        self.sizes = sizes
230	        self.max_size = max_size
231	
blacklist: Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Test ID: B311
Severity: LOW
Confidence: HIGH
CWE: CWE-330
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/datasets/transforms.py
Line number: 233
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b311-random
229	        self.sizes = sizes
230	        self.max_size = max_size
231	
232	    def __call__(self, img, target=None):
233	        size = random.choice(self.sizes)
234	        return resize(img, target, size, self.max_size)
235	
236	
blacklist: Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Test ID: B311
Severity: LOW
Confidence: HIGH
CWE: CWE-330
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/datasets/transforms.py
Line number: 242
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b311-random
238	    def __init__(self, max_pad):
239	        self.max_pad = max_pad
240	
241	    def __call__(self, img, target):
242	        pad_x = random.randint(0, self.max_pad)
243	        pad_y = random.randint(0, self.max_pad)
244	        return pad(img, target, (pad_x, pad_y))
245	
blacklist: Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Test ID: B311
Severity: LOW
Confidence: HIGH
CWE: CWE-330
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/datasets/transforms.py
Line number: 243
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b311-random
239	        self.max_pad = max_pad
240	
241	    def __call__(self, img, target):
242	        pad_x = random.randint(0, self.max_pad)
243	        pad_y = random.randint(0, self.max_pad)
244	        return pad(img, target, (pad_x, pad_y))
245	
246	
blacklist: Standard pseudo-random generators are not suitable for security/cryptographic purposes.
Test ID: B311
Severity: LOW
Confidence: HIGH
CWE: CWE-330
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/datasets/transforms.py
Line number: 259
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b311-random
255	        self.transforms2 = transforms2
256	        self.p = p
257	
258	    def __call__(self, img, target):
259	        if random.random() < self.p:
260	            return self.transforms1(img, target)
261	        return self.transforms2(img, target)
262	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/backbone.py
Line number: 112
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
108	        xs = self.body(tensor_list.tensors)
109	        out: Dict[str, NestedTensor] = {}
110	        for name, x in xs.items():
111	            m = tensor_list.mask
112	            assert m is not None
113	            mask = F.interpolate(m[None].float(), size=x.shape[-2:]).to(torch.bool)[0]
114	            out[name] = NestedTensor(x, mask)
115	        # import ipdb; ipdb.set_trace()
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/backbone.py
Line number: 139
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
135	            )
136	        else:
137	            raise NotImplementedError("Why you can get here with name {}".format(name))
138	        # num_channels = 512 if name in ('resnet18', 'resnet34') else 2048
139	        assert name not in ("resnet18", "resnet34"), "Only resnet50 and resnet101 are available."
140	        assert return_interm_indices in [[0, 1, 2, 3], [1, 2, 3], [3]]
141	        num_channels_all = [256, 512, 1024, 2048]
142	        num_channels = num_channels_all[4 - len(return_interm_indices) :]
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/backbone.py
Line number: 140
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
136	        else:
137	            raise NotImplementedError("Why you can get here with name {}".format(name))
138	        # num_channels = 512 if name in ('resnet18', 'resnet34') else 2048
139	        assert name not in ("resnet18", "resnet34"), "Only resnet50 and resnet101 are available."
140	        assert return_interm_indices in [[0, 1, 2, 3], [1, 2, 3], [3]]
141	        num_channels_all = [256, 512, 1024, 2048]
142	        num_channels = num_channels_all[4 - len(return_interm_indices) :]
143	        super().__init__(backbone, train_backbone, num_channels, return_interm_indices)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/backbone.py
Line number: 178
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
174	    train_backbone = True
175	    if not train_backbone:
176	        raise ValueError("Please set lr_backbone > 0")
177	    return_interm_indices = args.return_interm_indices
178	    assert return_interm_indices in [[0, 1, 2, 3], [1, 2, 3], [3]]
179	    args.backbone_freeze_keywords
180	    use_checkpoint = getattr(args, "use_checkpoint", False)
181	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/backbone.py
Line number: 211
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
207	        bb_num_channels = backbone.num_features[4 - len(return_interm_indices) :]
208	    else:
209	        raise NotImplementedError("Unknown backbone {}".format(args.backbone))
210	
211	    assert len(bb_num_channels) == len(
212	        return_interm_indices
213	    ), f"len(bb_num_channels) {len(bb_num_channels)} != len(return_interm_indices) {len(return_interm_indices)}"
214	
215	    model = Joiner(backbone, position_embedding)
216	    model.num_channels = bb_num_channels
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/backbone.py
Line number: 217
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
213	    ), f"len(bb_num_channels) {len(bb_num_channels)} != len(return_interm_indices) {len(return_interm_indices)}"
214	
215	    model = Joiner(backbone, position_embedding)
216	    model.num_channels = bb_num_channels
217	    assert isinstance(
218	        bb_num_channels, List
219	    ), "bb_num_channels is expected to be a List but {}".format(type(bb_num_channels))
220	    # import ipdb; ipdb.set_trace()
221	    return model
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/position_encoding.py
Line number: 50
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
46	
47	    def forward(self, tensor_list: NestedTensor):
48	        x = tensor_list.tensors
49	        mask = tensor_list.mask
50	        assert mask is not None
51	        not_mask = ~mask
52	        y_embed = not_mask.cumsum(1, dtype=torch.float32)
53	        x_embed = not_mask.cumsum(2, dtype=torch.float32)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/position_encoding.py
Line number: 101
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
97	
98	    def forward(self, tensor_list: NestedTensor):
99	        x = tensor_list.tensors
100	        mask = tensor_list.mask
101	        assert mask is not None
102	        not_mask = ~mask
103	        y_embed = not_mask.cumsum(1, dtype=torch.float32)
104	        x_embed = not_mask.cumsum(2, dtype=torch.float32)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/swin_transformer.py
Line number: 215
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
211	        self.num_heads = num_heads
212	        self.window_size = window_size
213	        self.shift_size = shift_size
214	        self.mlp_ratio = mlp_ratio
215	        assert 0 <= self.shift_size < self.window_size, "shift_size must in 0-window_size"
216	
217	        self.norm1 = norm_layer(dim)
218	        self.attn = WindowAttention(
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/swin_transformer.py
Line number: 247
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
243	            mask_matrix: Attention mask for cyclic shift.
244	        """
245	        B, L, C = x.shape
246	        H, W = self.H, self.W
247	        assert L == H * W, "input feature has wrong size"
248	
249	        shortcut = x
250	        x = self.norm1(x)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/swin_transformer.py
Line number: 321
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
317	            x: Input feature, tensor size (B, H*W, C).
318	            H, W: Spatial resolution of the input feature.
319	        """
320	        B, L, C = x.shape
321	        assert L == H * W, "input feature has wrong size"
322	
323	        x = x.view(B, H, W, C)
324	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/swin_transformer.py
Line number: 750
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
746	        # collect for nesttensors
747	        outs_dict = {}
748	        for idx, out_i in enumerate(outs):
749	            m = tensor_list.mask
750	            assert m is not None
751	            mask = F.interpolate(m[None].float(), size=out_i.shape[-2:]).to(torch.bool)[0]
752	            outs_dict[idx] = NestedTensor(out_i, mask)
753	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/backbone/swin_transformer.py
Line number: 763
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
759	        self._freeze_stages()
760	
761	
762	def build_swin_transformer(modelname, pretrain_img_size, **kw):
763	    assert modelname in [
764	        "swin_T_224_1k",
765	        "swin_B_224_22k",
766	        "swin_B_384_22k",
767	        "swin_L_224_22k",
768	        "swin_L_384_22k",
769	    ]
770	
771	    model_para_dict = {
772	        "swin_T_224_1k": dict(
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/fuse_modules.py
Line number: 109
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
105	        self.head_dim = embed_dim // num_heads
106	        self.v_dim = v_dim
107	        self.l_dim = l_dim
108	
109	        assert (
110	            self.head_dim * self.num_heads == self.embed_dim
111	        ), f"embed_dim must be divisible by num_heads (got `embed_dim`: {self.embed_dim} and `num_heads`: {self.num_heads})."
112	        self.scale = self.head_dim ** (-0.5)
113	        self.dropout = dropout
114	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/groundingdino.py
Line number: 87
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
83	        self.sub_sentence_present = sub_sentence_present
84	
85	        # setting query dim
86	        self.query_dim = query_dim
87	        assert query_dim == 4
88	
89	        # for dn training
90	        self.num_patterns = num_patterns
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/groundingdino.py
Line number: 133
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
129	                )
130	                in_channels = hidden_dim
131	            self.input_proj = nn.ModuleList(input_proj_list)
132	        else:
133	            assert two_stage_type == "no", "two_stage_type should be no if num_feature_levels=1 !!!"
134	            self.input_proj = nn.ModuleList(
135	                [
136	                    nn.Sequential(
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/groundingdino.py
Line number: 148
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
144	        self.aux_loss = aux_loss
145	        self.box_pred_damping = box_pred_damping = None
146	
147	        self.iter_update = iter_update
148	        assert iter_update, "Why not iter_update?"
149	
150	        # prepare pred layers
151	        self.dec_pred_bbox_embed_share = dec_pred_bbox_embed_share
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/groundingdino.py
Line number: 173
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
169	        self.transformer.decoder.class_embed = self.class_embed
170	
171	        # two stage
172	        self.two_stage_type = two_stage_type
173	        assert two_stage_type in ["no", "standard"], "unknown param {} of two_stage_type".format(
174	            two_stage_type
175	        )
176	        if two_stage_type != "no":
177	            if two_stage_bbox_embed_share:
178	                assert dec_pred_bbox_embed_share
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/groundingdino.py
Line number: 178
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
174	            two_stage_type
175	        )
176	        if two_stage_type != "no":
177	            if two_stage_bbox_embed_share:
178	                assert dec_pred_bbox_embed_share
179	                self.transformer.enc_out_bbox_embed = _bbox_embed
180	            else:
181	                self.transformer.enc_out_bbox_embed = copy.deepcopy(_bbox_embed)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/groundingdino.py
Line number: 184
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
180	            else:
181	                self.transformer.enc_out_bbox_embed = copy.deepcopy(_bbox_embed)
182	
183	            if two_stage_class_embed_share:
184	                assert dec_pred_bbox_embed_share
185	                self.transformer.enc_out_class_embed = _class_embed
186	            else:
187	                self.transformer.enc_out_class_embed = copy.deepcopy(_class_embed)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/groundingdino.py
Line number: 287
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
283	        for l, feat in enumerate(features):
284	            src, mask = feat.decompose()
285	            srcs.append(self.input_proj[l](src))
286	            masks.append(mask)
287	            assert mask is not None
288	        if self.num_feature_levels > len(srcs):
289	            _len_srcs = len(srcs)
290	            for l in range(_len_srcs, self.num_feature_levels):
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/ms_deform_attn.py
Line number: 228
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
224	
225	        bs, num_query, _ = query.shape
226	        bs, num_value, _ = value.shape
227	
228	        assert (spatial_shapes[:, 0] * spatial_shapes[:, 1]).sum() == num_value
229	
230	        value = self.value_proj(value)
231	        if key_padding_mask is not None:
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 81
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
77	        self.num_encoder_layers = num_encoder_layers
78	        self.num_unicoder_layers = num_unicoder_layers
79	        self.num_decoder_layers = num_decoder_layers
80	        self.num_queries = num_queries
81	        assert query_dim == 4
82	
83	        # choose encoder layer type
84	        encoder_layer = DeformableTransformerEncoderLayer(
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 111
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
107	        else:
108	            feature_fusion_layer = None
109	
110	        encoder_norm = nn.LayerNorm(d_model) if normalize_before else None
111	        assert encoder_norm is None
112	        self.encoder = TransformerEncoder(
113	            encoder_layer,
114	            num_encoder_layers,
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 162
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
158	            else:
159	                self.level_embed = None
160	
161	        self.learnable_tgt_init = learnable_tgt_init
162	        assert learnable_tgt_init, "why not learnable_tgt_init"
163	        self.embed_init_tgt = embed_init_tgt
164	        if (two_stage_type != "no" and embed_init_tgt) or (two_stage_type == "no"):
165	            self.tgt_embed = nn.Embedding(self.num_queries, d_model)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 172
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
168	            self.tgt_embed = None
169	
170	        # for two stage
171	        self.two_stage_type = two_stage_type
172	        assert two_stage_type in ["no", "standard"], "unknown param {} of two_stage_type".format(
173	            two_stage_type
174	        )
175	        if two_stage_type == "standard":
176	            # anchor selection at the output of encoder
177	            self.enc_output = nn.Linear(d_model, d_model)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 617
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
613	            self.layers = []
614	        self.num_layers = num_layers
615	        self.norm = norm
616	        self.return_intermediate = return_intermediate
617	        assert return_intermediate, "support return_intermediate only"
618	        self.query_dim = query_dim
619	        assert query_dim in [2, 4], "query_dim should be 2/4 but {}".format(query_dim)
620	        self.num_feature_levels = num_feature_levels
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 619
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
615	        self.norm = norm
616	        self.return_intermediate = return_intermediate
617	        assert return_intermediate, "support return_intermediate only"
618	        self.query_dim = query_dim
619	        assert query_dim in [2, 4], "query_dim should be 2/4 but {}".format(query_dim)
620	        self.num_feature_levels = num_feature_levels
621	
622	        self.ref_point_head = MLP(query_dim // 2 * d_model, d_model, d_model, 2)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 673
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
669	                    reference_points[:, :, None]
670	                    * torch.cat([valid_ratios, valid_ratios], -1)[None, :]
671	                )  # nq, bs, nlevel, 4
672	            else:
673	                assert reference_points.shape[-1] == 2
674	                reference_points_input = reference_points[:, :, None] * valid_ratios[None, :]
675	            query_sine_embed = gen_sineembed_for_position(
676	                reference_points_input[:, :, 0, :]
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 849
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
845	        self.norm3 = nn.LayerNorm(d_model)
846	
847	        self.key_aware_proj = None
848	        self.use_text_feat_guide = use_text_feat_guide
849	        assert not use_text_feat_guide
850	        self.use_text_cross_attention = use_text_cross_attention
851	
852	    def rm_self_attn_modules(self):
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/transformer.py
Line number: 893
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
889	        Input:
890	            - tgt/tgt_query_pos: nq, bs, d_model
891	            -
892	        """
893	        assert cross_attn_mask is None
894	
895	        # self attention
896	        if self.self_attn is not None:
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/GroundingDINO/utils.py
Line number: 256
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
252	            }
253	        Returns:
254	            _type_: _description_
255	        """
256	        assert isinstance(text_dict, dict)
257	
258	        y = text_dict["encoded_text"]
259	        text_token_mask = text_dict["text_token_mask"]
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/models/__init__.py
Line number: 15
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
11	def build_model(args):
12	    # we use register to maintain models from catdet6 on.
13	    from .registry import MODULE_BUILD_FUNCS
14	
15	    assert args.modelname in MODULE_BUILD_FUNCS._module_dict
16	    build_func = MODULE_BUILD_FUNCS.get(args.modelname)
17	    model = build_func(args)
18	    return model
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/box_ops.py
Line number: 50
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
46	    and M = len(boxes2)
47	    """
48	    # degenerate boxes gives inf / nan results
49	    # so do an early check
50	    assert (boxes1[:, 2:] >= boxes1[:, :2]).all()
51	    assert (boxes2[:, 2:] >= boxes2[:, :2]).all()
52	    # except:
53	    #     import ipdb; ipdb.set_trace()
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/box_ops.py
Line number: 51
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
47	    """
48	    # degenerate boxes gives inf / nan results
49	    # so do an early check
50	    assert (boxes1[:, 2:] >= boxes1[:, :2]).all()
51	    assert (boxes2[:, 2:] >= boxes2[:, :2]).all()
52	    # except:
53	    #     import ipdb; ipdb.set_trace()
54	    iou, union = box_iou(boxes1, boxes2)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/box_ops.py
Line number: 93
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
89	        - giou: N, 4
90	    """
91	    # degenerate boxes gives inf / nan results
92	    # so do an early check
93	    assert (boxes1[:, 2:] >= boxes1[:, :2]).all()
94	    assert (boxes2[:, 2:] >= boxes2[:, :2]).all()
95	    assert boxes1.shape == boxes2.shape
96	    iou, union = box_iou_pairwise(boxes1, boxes2)  # N, 4
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/box_ops.py
Line number: 94
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
90	    """
91	    # degenerate boxes gives inf / nan results
92	    # so do an early check
93	    assert (boxes1[:, 2:] >= boxes1[:, :2]).all()
94	    assert (boxes2[:, 2:] >= boxes2[:, :2]).all()
95	    assert boxes1.shape == boxes2.shape
96	    iou, union = box_iou_pairwise(boxes1, boxes2)  # N, 4
97	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/box_ops.py
Line number: 95
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
91	    # degenerate boxes gives inf / nan results
92	    # so do an early check
93	    assert (boxes1[:, 2:] >= boxes1[:, :2]).all()
94	    assert (boxes2[:, 2:] >= boxes2[:, :2]).all()
95	    assert boxes1.shape == boxes2.shape
96	    iou, union = box_iou_pairwise(boxes1, boxes2)  # N, 4
97	
98	    lt = torch.min(boxes1[:, :2], boxes2[:, :2])
blacklist: Consider possible security implications associated with pickle module.
Test ID: B403
Severity: LOW
Confidence: HIGH
CWE: CWE-502
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 13
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_imports.html#b403-import-pickle
9	import functools
10	import io
11	import json
12	import os
13	import pickle
14	import subprocess
15	import time
16	from collections import OrderedDict, defaultdict, deque
blacklist: Consider possible security implications associated with the subprocess module.
Test ID: B404
Severity: LOW
Confidence: HIGH
CWE: CWE-78
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 14
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_imports.html#b404-import-subprocess
10	import io
11	import json
12	import os
13	import pickle
14	import subprocess
15	import time
16	from collections import OrderedDict, defaultdict, deque
17	from typing import List, Optional
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 146
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
142	        print("gathering on cpu")
143	        dist.all_gather(size_list, local_size, group=cpu_group)
144	    size_list = [int(size.item()) for size in size_list]
145	    max_size = max(size_list)
146	    assert isinstance(local_size.item(), int)
147	    local_size = int(local_size.item())
148	
149	    # receiving Tensor from all ranks
blacklist: Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.
Test ID: B301
Severity: MEDIUM
Confidence: HIGH
CWE: CWE-502
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 215
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b301-pickle
211	
212	    data_list = []
213	    for size, tensor in zip(size_list, tensor_list):
214	        buffer = tensor.cpu().numpy().tobytes()[:size]
215	        data_list.append(pickle.loads(buffer))
216	
217	    return data_list
218	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 256
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
252	    def update(self, **kwargs):
253	        for k, v in kwargs.items():
254	            if isinstance(v, torch.Tensor):
255	                v = v.item()
256	            assert isinstance(v, (float, int))
257	            self.meters[k].update(v)
258	
259	    def __getattr__(self, attr):
subprocess_without_shell_equals_true: subprocess call - check for execution of untrusted input.
Test ID: B603
Severity: LOW
Confidence: HIGH
CWE: CWE-78
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 366
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b603_subprocess_without_shell_equals_true.html
362	def get_sha():
363	    cwd = os.path.dirname(os.path.abspath(__file__))
364	
365	    def _run(command):
366	        return subprocess.check_output(command, cwd=cwd).decode("ascii").strip()
367	
368	    sha = "N/A"
369	    diff = "clean"
start_process_with_partial_path: Starting a process with a partial executable path
Test ID: B607
Severity: LOW
Confidence: HIGH
CWE: CWE-78
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 373
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b607_start_process_with_partial_path.html
369	    diff = "clean"
370	    branch = "N/A"
371	    try:
372	        sha = _run(["git", "rev-parse", "HEAD"])
373	        subprocess.check_output(["git", "diff"], cwd=cwd)
374	        diff = _run(["git", "diff-index", "HEAD"])
375	        diff = "has uncommited changes" if diff else "clean"
376	        branch = _run(["git", "rev-parse", "--abbrev-ref", "HEAD"])
subprocess_without_shell_equals_true: subprocess call - check for execution of untrusted input.
Test ID: B603
Severity: LOW
Confidence: HIGH
CWE: CWE-78
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 373
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b603_subprocess_without_shell_equals_true.html
369	    diff = "clean"
370	    branch = "N/A"
371	    try:
372	        sha = _run(["git", "rev-parse", "HEAD"])
373	        subprocess.check_output(["git", "diff"], cwd=cwd)
374	        diff = _run(["git", "diff-index", "HEAD"])
375	        diff = "has uncommited changes" if diff else "clean"
376	        branch = _run(["git", "rev-parse", "--abbrev-ref", "HEAD"])
try_except_pass: Try, Except, Pass detected.
Test ID: B110
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 377
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b110_try_except_pass.html
373	        subprocess.check_output(["git", "diff"], cwd=cwd)
374	        diff = _run(["git", "diff-index", "HEAD"])
375	        diff = "has uncommited changes" if diff else "clean"
376	        branch = _run(["git", "rev-parse", "--abbrev-ref", "HEAD"])
377	    except Exception:
378	        pass
379	    message = f"sha: {sha}, status: {diff}, branch: {branch}"
380	    return message
381	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 430
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
426	        # type: (Device) -> NestedTensor # noqa
427	        cast_tensor = self.tensors.to(device)
428	        mask = self.mask
429	        if mask is not None:
430	            assert mask is not None
431	            cast_mask = mask.to(device)
432	        else:
433	            cast_mask = None
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/misc.py
Line number: 437
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
433	            cast_mask = None
434	        return NestedTensor(cast_tensor, cast_mask)
435	
436	    def to_img_list_single(self, tensor, mask):
437	        assert tensor.dim() == 3, "dim of tensor should be 3 but {}".format(tensor.dim())
438	        maxH = (~mask).sum(0).max()
439	        maxW = (~mask).sum(1).max()
440	        img = tensor[:, :maxH, :maxW]
blacklist: Consider possible security implications associated with pickle module.
Test ID: B403
Severity: LOW
Confidence: HIGH
CWE: CWE-502
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/slio.py
Line number: 6
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_imports.html#b403-import-pickle
2	# Modified from mmcv
3	# ==========================================================
4	
5	import json
6	import pickle
7	from abc import ABCMeta, abstractmethod
8	from pathlib import Path
9	
blacklist: Pickle and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue.
Test ID: B301
Severity: MEDIUM
Confidence: HIGH
CWE: CWE-502
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/slio.py
Line number: 58
More info: https://bandit.readthedocs.io/en/1.7.9/blacklists/blacklist_calls.html#b301-pickle
54	
55	
56	class PickleHandler(BaseFileHandler):
57	    def load_from_fileobj(self, file, **kwargs):
58	        return pickle.load(file, **kwargs)
59	
60	    def load_from_path(self, filepath, **kwargs):
61	        return super(PickleHandler, self).load_from_path(filepath, mode="rb", **kwargs)
yaml_load: Use of unsafe yaml load. Allows instantiation of arbitrary objects. Consider yaml.safe_load().
Test ID: B506
Severity: MEDIUM
Confidence: HIGH
CWE: CWE-20
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/slio.py
Line number: 78
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b506_yaml_load.html
74	
75	class YamlHandler(BaseFileHandler):
76	    def load_from_fileobj(self, file, **kwargs):
77	        kwargs.setdefault("Loader", Loader)
78	        return yaml.load(file, **kwargs)
79	
80	    def dump_to_fileobj(self, obj, file, **kwargs):
81	        kwargs.setdefault("Dumper", Dumper)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/utils.py
Line number: 43
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
39	    img: torch.FloatTensor, mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]
40	) -> torch.FloatTensor:
41	    # img: tensor(3,H,W) or tensor(B,3,H,W)
42	    # return: same as img
43	    assert img.dim() == 3 or img.dim() == 4, "img.dim() should be 3 or 4 but %d" % img.dim()
44	    if img.dim() == 3:
45	        assert img.size(0) == 3, 'img.size(0) shoule be 3 but "%d". (%s)' % (
46	            img.size(0),
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/utils.py
Line number: 45
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
41	    # img: tensor(3,H,W) or tensor(B,3,H,W)
42	    # return: same as img
43	    assert img.dim() == 3 or img.dim() == 4, "img.dim() should be 3 or 4 but %d" % img.dim()
44	    if img.dim() == 3:
45	        assert img.size(0) == 3, 'img.size(0) shoule be 3 but "%d". (%s)' % (
46	            img.size(0),
47	            str(img.size()),
48	        )
49	        img_perm = img.permute(1, 2, 0)
50	        mean = torch.Tensor(mean)
51	        std = torch.Tensor(std)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/utils.py
Line number: 55
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
51	        std = torch.Tensor(std)
52	        img_res = img_perm * std + mean
53	        return img_res.permute(2, 0, 1)
54	    else:  # img.dim() == 4
55	        assert img.size(1) == 3, 'img.size(1) shoule be 3 but "%d". (%s)' % (
56	            img.size(1),
57	            str(img.size()),
58	        )
59	        img_perm = img.permute(0, 2, 3, 1)
60	        mean = torch.Tensor(mean)
61	        std = torch.Tensor(std)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/utils.py
Line number: 287
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
283	        """
284	        Input:
285	            pred, gt: Tensor()
286	        """
287	        assert pred.shape == gt.shape
288	        self.tp += torch.logical_and(pred == 1, gt == 1).sum().item()
289	        self.fp += torch.logical_and(pred == 1, gt == 0).sum().item()
290	        self.tn += torch.logical_and(pred == 0, gt == 0).sum().item()
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/utils.py
Line number: 326
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
322	        raise NotImplementedError("Unknown type {}".format(type(args)))
323	
324	
325	def stat_tensors(tensor):
326	    assert tensor.dim() == 1
327	    tensor_sm = tensor.softmax(0)
328	    entropy = (tensor_sm * torch.log(tensor_sm + 1e-9)).sum()
329	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/utils.py
Line number: 510
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
506	        self.best_res = init_res
507	        self.best_ep = -1
508	
509	        self.better = better
510	        assert better in ["large", "small"]
511	
512	    def isbetter(self, new_res, old_res):
513	        if self.better == "large":
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/local_groundingdino/util/utils.py
Line number: 602
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
598	
599	def get_phrases_from_posmap(
600	    posmap: torch.BoolTensor, tokenized: Dict, tokenizer: AutoTokenizer
601	):
602	    assert isinstance(posmap, torch.Tensor), "posmap must be torch.Tensor"
603	    if posmap.dim() == 1:
604	        non_zero_idx = posmap.nonzero(as_tuple=True)[0].tolist()
605	        token_ids = [tokenized["input_ids"][i] for i in non_zero_idx]
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/automatic.py
Line number: 79
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
75	            For large resolutions, 'binary_mask' may consume large amounts of
76	            memory.
77	        """
78	
79	        assert (points_per_side is None) != (
80	            point_grids is None
81	        ), "Exactly one of points_per_side or point_grid must be provided."
82	        if points_per_side is not None:
83	            self.point_grids = build_all_layer_point_grids(
84	                points_per_side,
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/automatic.py
Line number: 93
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
89	            self.point_grids = point_grids
90	        else:
91	            raise ValueError("Can't have both points_per_side and point_grid be None.")
92	
93	        assert output_mode in [
94	            "binary_mask",
95	            "uncompressed_rle",
96	            "coco_rle",
97	        ], f"Unknown output_mode {output_mode}."
98	        if output_mode == "coco_rle":
99	            from pycocotools import mask as mask_utils  # type: ignore # noqa: F401
100	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/modeling/tiny_vit.py
Line number: 219
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
215	                 resolution=(14, 14),
216	                 ):
217	        super().__init__()
218	        # (h, w)
219	        assert isinstance(resolution, tuple) and len(resolution) == 2
220	        self.num_heads = num_heads
221	        self.scale = key_dim ** -0.5
222	        self.key_dim = key_dim
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/modeling/tiny_vit.py
Line number: 310
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
306	        super().__init__()
307	        self.dim = dim
308	        self.input_resolution = input_resolution
309	        self.num_heads = num_heads
310	        assert window_size > 0, 'window_size must be greater than 0'
311	        self.window_size = window_size
312	        self.mlp_ratio = mlp_ratio
313	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/modeling/tiny_vit.py
Line number: 317
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
313	
314	        self.drop_path = DropPath(
315	            drop_path) if drop_path > 0. else nn.Identity()
316	
317	        assert dim % num_heads == 0, 'dim must be divisible by num_heads'
318	        head_dim = dim // num_heads
319	
320	        window_resolution = (window_size, window_size)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/modeling/tiny_vit.py
Line number: 336
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
332	
333	    def forward(self, x):
334	        H, W = self.input_resolution
335	        B, L, C = x.shape
336	        assert L == H * W, "input feature has wrong size"
337	        res_x = x
338	        if H == self.window_size and W == self.window_size:
339	            x = self.attn(x)
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/modeling/tiny_vit.py
Line number: 572
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
568	                i += 1
569	            if layer.downsample is not None:
570	                layer.downsample.apply(
571	                    lambda x: _set_lr_scale(x, lr_scales[i - 1]))
572	        assert i == depth
573	        for m in [self.norm_head, self.head]:
574	            m.apply(lambda x: _set_lr_scale(x, lr_scales[-1]))
575	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/modeling/tiny_vit.py
Line number: 581
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
577	            p.param_name = k
578	
579	        def _check_lr_scale(m):
580	            for p in m.parameters():
581	                assert hasattr(p, 'lr_scale'), p.param_name
582	
583	        self.apply(_check_lr_scale)
584	
assert_used: Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Test ID: B101
Severity: LOW
Confidence: HIGH
CWE: CWE-703
File: /custom_nodes/comfyui_segment_anything/sam_hq/predictor.py
Line number: 43
More info: https://bandit.readthedocs.io/en/1.7.9/plugins/b101_assert_used.html
39	            1x3xHxW, which has been transformed with ResizeLongestSide.
40	          original_image_size (tuple(int, int)): The size of the image
41	            before transformation, in (H, W) format.
42	        """
43	        assert (
44	            len(transformed_image.shape) == 4
45	            and transformed_image.shape[1] == 3
46	            and max(*transformed_image.shape[2:]) == self.model.image_encoder.img_size
47	        ), f"set_torch_image input must be BCHW with long side {self.model.image_encoder.img_size}."
48	        self.reset_image()
49	
50	        self.original_size = original_image_size