tuyunbin / SCORER

[ICCV 2023] This is the Pytorch code for our paper "Self-Supervised Cross-View Representation Reconstruction for Change Captioning".
14 stars 1 forks source link

AttributeError: 'ChangeDetector' object has no attribute 'cross_layer' #2

Closed matthewdm0816 closed 6 months ago

matthewdm0816 commented 7 months ago

Running the training script seems lead to an error. The command: python train.py --cfg configs/dynamic/transformer.yaml The error:

Traceback (most recent call last):
  File "train.py", line 223, in <module>
    torch.clamp_(change_detector.cross_layer[-1].self_attention.logit_scale.data, max=np.log(100))
  File "/hd1/mwt/miniconda3/envs/scorer/lib/python3.8/site-packages/torch/nn/modules/module.py", line 947, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'ChangeDetector' object has no attribute 'cross_layer'

The related code: https://github.com/tuyunbin/SCORER/blob/5bd189c5198179f1cd62a0e2e03184c2efdb9706/train.py#L219-L226 In SCORER.py, seems I can't find cross_layer attributes. And since it seems a this is only for logging, I commented these lines and the trainining seems to continue.

tuyunbin commented 7 months ago

you can try changing cross_layer as scorer

---Original--- From: "Kazami @.> Date: Thu, Dec 7, 2023 21:06 PM To: @.>; Cc: @.***>; Subject: [tuyunbin/SCORER] AttributeError: 'ChangeDetector' object has noattribute 'cross_layer' (Issue #2)

Running the training script seems lead to an error. The command: python train.py --cfg configs/dynamic/transformer.yaml The error: Traceback (most recent call last): File "train.py", line 223, in <module> torch.clamp_(change_detector.cross_layer[-1].self_attention.logit_scale.data, max=np.log(100)) File "/hd1/mwt/miniconda3/envs/scorer/lib/python3.8/site-packages/torch/nn/modules/module.py", line 947, in getattr raise AttributeError("'{}' object has no attribute '{}'".format( AttributeError: 'ChangeDetector' object has no attribute 'cross_layer'
The related code: https://github.com/tuyunbin/SCORER/blob/5bd189c5198179f1cd62a0e2e03184c2efdb9706/train.py#L219-L226 In SCORER.py, seems I can't find cross_layer attributes. And since it seems a this is only for logging, I commented these lines and the trainining seems to continue.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

matthewdm0816 commented 7 months ago

And replace .self_attention to .attention as well, like:

if hasattr(change_detector, 'module'):
  torch.clamp_(change_detector.scorer.attention.module.logit_scale.data, max=np.log(100))
  logit_scale = change_detector.scorer.attention.module.logit_scale.exp().item()
else:
  torch.clamp_(change_detector.scorer[-1].attention.logit_scale.data, max=np.log(100))
  logit_scale = change_detector.scorer[-1].attention.logit_scale.exp().item()
  torch.clamp_(generator.contra.logit_scale.data, max=np.log(100))
  logit_scale_cycle = generator.contra.logit_scale.exp().item()

And thank you for your fast reply!

tuyunbin commented 7 months ago

Thank you for pointing out these errors.