metadriverse / trafficgen

[ICRA 2023] The official code for paper "TrafficGen: Learning to Generate Diverse and Realistic Traffic Scenarios"
Apache License 2.0
153 stars 24 forks source link

Question regarding tg_act.py file #36

Closed hchaozhe closed 1 year ago

hchaozhe commented 1 year ago

Thank you for sharing this nice work! I have a question regarding the tg_act.py. I encounter error when trying to run the train_act.py script. I encountered error points towards the following two lines.

  File "xxx/trafficgen/trafficgen/act/model/tg_act.py", line 105, in training_step
    loss_dict = {'train/' + k: v for k, v in loss.items()}
AttributeError: 'Tensor' object has no attribute 'items'

Seems to me that loss is a tensor that indeed does not have .items field, and the loss_dict is already returned by the act_loss function.

I commented out these two lines and I was able to run the script. I wonder if these two lines are redundant?

https://github.com/metadriverse/trafficgen/blob/162add314dc0a1f63a4e39c2d51159349df8baef/trafficgen/act/model/tg_act.py#L105

https://github.com/metadriverse/trafficgen/blob/162add314dc0a1f63a4e39c2d51159349df8baef/trafficgen/act/model/tg_act.py#L112

melon7489 commented 1 year ago

Thank you for sharing this nice work! I have a question regarding the tg_act.py. I encounter error when trying to run the train_act.py script. I encountered error points towards the following two lines.

  File "xxx/trafficgen/trafficgen/act/model/tg_act.py", line 105, in training_step
    loss_dict = {'train/' + k: v for k, v in loss.items()}
AttributeError: 'Tensor' object has no attribute 'items'

Seems to me that loss is a tensor that indeed does not have .items field, and the loss_dict is already returned by the act_loss function.

I commented out these two lines and I was able to run the script. I wonder if these two lines are redundant?

https://github.com/metadriverse/trafficgen/blob/162add314dc0a1f63a4e39c2d51159349df8baef/trafficgen/act/model/tg_act.py#L105

https://github.com/metadriverse/trafficgen/blob/162add314dc0a1f63a4e39c2d51159349df8baef/trafficgen/act/model/tg_act.py#L112

Hello, have you resolved the problem? There are “items()” in dict in Python, and I guess the “loss. items()” here should be “loss_ dict. items()”, but I'm not sure. But after I made the changes, the code did run successfully.

Alan-LanFeng commented 1 year ago

Hi, thanks for asking.

There's a bug with these two lines of code, just make sure you are logging a dict with pytorch-lightning. You are doing it correctly!