Removed extraneous print statements
Browse files236 unmodified lines23723823924024024124230 unmodified lines2732742752772762772787 unmodified lines2862872882912892902918 unmodified lines30030130230630330430531030630730810 unmodified lines31932032132732232932332432532632733532833732933033134134233233333433533633734933833934048 unmodified lines3893903914043923933948 unmodified lines403404405419406407408137 unmodified lines54654754856354955055124 unmodified lines5765775785945795805975815825831 unmodified line5855865876055886075895905915925935946145955966175975985996006016026246036046056286066076083 unmodified lines6126136146386156406166176182 unmodified lines621622623649624625626194 unmodified lines821822823850824825826236 unmodified lines
""" # prepare input for encoder print("inside transformer forward") src_flatten = [] mask_flatten = [] lvl_pos_embed_flatten = []30 unmodified lines ######################################################### # Begin Encoder ######################################################### print("begin transformer encoder") memory, memory_text = self.encoder( src_flatten, pos=lvl_pos_embed_flatten,7 unmodified lines position_ids=text_dict["position_ids"], text_self_attention_masks=text_dict["text_self_attention_masks"], ) print("got encoder output") ######################################################### # End Encoder # - memory: bs, \sum{hw}, c8 unmodified lines # import ipdb; ipdb.set_trace()
if self.two_stage_type == "standard": # 把encoder的输出作为proposal print("standard two stage") output_memory, output_proposals = gen_encoder_output_proposals( memory, mask_flatten, spatial_shapes ) print("got output proposals") output_memory = self.enc_output_norm(self.enc_output(output_memory))
if text_dict is not None:10 unmodified lines topk = self.num_queries
topk_proposals = torch.topk(topk_logits, topk, dim=1)[1] # bs, nq print("got topk proposals") # gather boxes print("gather 1") refpoint_embed_undetach = torch.gather( enc_outputs_coord_unselected, 1, topk_proposals.unsqueeze(-1).repeat(1, 1, 4), ) # unsigmoid print("gathered 1") refpoint_embed_ = refpoint_embed_undetach.detach() print("gather 2") init_box_proposal = torch.gather( output_proposals, 1, topk_proposals.unsqueeze(-1).repeat(1, 1, 4) ).sigmoid() # sigmoid print("gathered 2") print("gather 3") # gather tgt tgt_undetach = torch.gather( output_memory, 1, topk_proposals.unsqueeze(-1).repeat(1, 1, self.d_model), ) print("gathered 3") if self.embed_init_tgt: tgt_ = ( self.tgt_embed.weight[:, None, :].repeat(1, bs, 1).transpose(0, 1)48 unmodified lines # memory torch.Size([2, 16320, 256])
# import pdb;pdb.set_trace() print("going through decoder") hs, references = self.decoder( tgt=tgt.transpose(0, 1), memory=memory.transpose(0, 1),8 unmodified lines text_attention_mask=~text_dict["text_token_mask"], # we ~ the mask . False means use the token; True means pad the token ) print("got decoder output") ######################################################### # End Decoder # hs: n_dec, bs, nq, d_model137 unmodified lines """
output = src print("inside transformer encoder") # preparation and reshape if self.num_layers > 0: reference_points = self.get_reference_points(24 unmodified lines # if output.isnan().any() or memory_text.isnan().any(): # if os.environ.get('IPDB_SHILONG_DEBUG', None) == 'INFO': # import ipdb; ipdb.set_trace() print("layer_id: " + str(layer_id)) if self.fusion_layers: if self.use_checkpoint: print("using checkpoint") output, memory_text = checkpoint.checkpoint( self.fusion_layers[layer_id], output,1 unmodified line key_padding_mask, text_attention_mask, ) print("got checkpoint output") else: print("not using checkpoint") output, memory_text = self.fusion_layers[layer_id]( v=output, l=memory_text, attention_mask_v=key_padding_mask, attention_mask_l=text_attention_mask, ) print("got fusion output")
if self.text_layers: print("getting text layers") memory_text = self.text_layers[layer_id]( src=memory_text.transpose(0, 1), src_mask=~text_self_attention_masks, # note we use ~ for mask here src_key_padding_mask=text_attention_mask, pos=(pos_text.transpose(0, 1) if pos_text is not None else None), ).transpose(0, 1) print("got text output")
# main process if self.use_transformer_ckpt: print("use transformer ckpt") output = checkpoint.checkpoint( layer, output,3 unmodified lines level_start_index, key_padding_mask, ) print("got output") else: print("not use transformer ckpt") output = layer( src=output, pos=pos,2 unmodified lines level_start_index=level_start_index, key_padding_mask=key_padding_mask, ) print("got output")
return output, memory_text
194 unmodified lines ): # self attention # import ipdb; ipdb.set_trace() print("deformable self-attention") src2 = self.self_attn( query=self.with_pos_embed(src, pos), reference_points=reference_points,models/GroundingDINO/transformer.py-27