LightZero icon indicating copy to clipboard operation
LightZero copied to clipboard

Unexpected Negative Values for Perceptual Loss in UniZero Implementation

Open Tiikara opened this issue 1 year ago • 3 comments

I am currently conducting experiments with the UniZero neural network using your library. During my research, I've observed that when incorporating perceptual loss in the UniZero model, the loss values are consistently negative. This behavior seems counterintuitive, as loss values are typically non-negative.

Could you please clarify if this is the expected behavior for perceptual loss in UniZero, or if it potentially indicates an issue in the implementation? Any insights or guidance on this matter would be greatly appreciated.

Thank you for your attention to this query.

Tiikara avatar Aug 01 '24 08:08 Tiikara

Thank you very much for your question. Are you referring to the negative loss value as perceptual loss or some other type of loss? In our previous experiments that included perceptual loss, the perceptual loss has always been a positive value, and we have never encountered a negative value situation. Please provide more information so that we can better analyze the issue. Thank you.

puyuan1996 avatar Aug 02 '24 06:08 puyuan1996

Thank you for your prompt reply. Indeed, in my experiments, I observed negative values for perceptual loss in TensorBoard. Upon examining the code, I believe these values are derived from the NetLinLayer model, which concludes with a convolutional layer.

I'm wondering if there might be an issue with how the model is being loaded in my setup. In my experiments, I'm using a slightly modified version of the LatentDecoder model. The key difference is that my version ends with a Conv2d layer instead of the ConvTranspose2d layer present in the current master branch code. This is the only deviation from the existing implementation.

https://github.com/Tiikara/LightZero/blob/9a1da08424a7c61eda9b41d9b46b21f911f5404e/lzero/model/exts/latent_decoder_espcn.py#L19-L72

Could this architectural difference potentially explain the negative perceptual loss values? I'd appreciate your insights on whether this modification could lead to such unexpected behavior.

Tiikara avatar Aug 02 '24 07:08 Tiikara

Using a Conv2d layer may change the resolution of the output feature map, thereby affecting the calculation of perceptual loss. My suggestions are as follows:

  1. Restore the original architecture: Revert the model's final layer back to ConvTranspose2d and observe whether the perceptual loss value returns to normal.
  2. Check the output feature map: In the modified model, carefully inspect the decoder's output feature map to ensure its resolution and quality meet expectations.
  3. Debug perceptual loss calculation: Print intermediate results of the perceptual loss calculation and check the differences between feature maps to identify the root cause of any anomalies in the perceptual loss.

puyuan1996 avatar Aug 02 '24 09:08 puyuan1996