prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  paddleseg/models/hrnet_contrast.py 中没有执行 init_weight
  paddleseg/models/hrnet_contrast.py 中__init__()没有执行 init_weight，导致hrnet_w48_contrast 没法加载完整的模型
  
  </issue>
  <code>
  [start of paddleseg/models/hrnet_contrast.py]
  1 # Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #    http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 
  15 import paddle
  16 import paddle.nn as nn
  17 import paddle.nn.functional as F
  18 
  19 from paddleseg.cvlibs import manager
  20 from paddleseg.models import layers
  21 from paddleseg.utils import utils
  22 
  23 
  24 @manager.MODELS.add_component
  25 class HRNetW48Contrast(nn.Layer):
  26     """
  27     The HRNetW48Contrast implementation based on PaddlePaddle.
  28 
  29     The original article refers to
  30     Wenguan Wang, Tianfei Zhou, et al. "Exploring Cross-Image Pixel Contrast for Semantic Segmentation"
  31     (https://arxiv.org/abs/2101.11939).
  32 
  33     Args:
  34         in_channels (int): The output dimensions of backbone.
  35         num_classes (int): The unique number of target classes.
  36         backbone (Paddle.nn.Layer): Backbone network, currently support HRNet_W48.
  37         drop_prob (float): The probability of dropout.
  38         proj_dim (int): The projection dimensions.
  39         align_corners (bool, optional): An argument of F.interpolate. It should be set to False when the feature size is even,
  40             e.g. 1024x512, otherwise it is True, e.g. 769x769. Default: False.
  41         pretrained (str, optional): The path or url of pretrained model. Default: None.
  42     """
  43     def __init__(self,
  44                  in_channels,
  45                  num_classes,
  46                  backbone,
  47                  drop_prob,
  48                  proj_dim,
  49                  align_corners=False,
  50                  pretrained=None):
  51         super().__init__()
  52         self.in_channels = in_channels
  53         self.backbone = backbone
  54         self.num_classes = num_classes
  55         self.proj_dim = proj_dim
  56         self.align_corners = align_corners
  57         self.pretrained = pretrained
  58 
  59         self.cls_head = nn.Sequential(
  60             layers.ConvBNReLU(in_channels,
  61                               in_channels,
  62                               kernel_size=3,
  63                               stride=1,
  64                               padding=1),
  65             nn.Dropout2D(drop_prob),
  66             nn.Conv2D(in_channels,
  67                       num_classes,
  68                       kernel_size=1,
  69                       stride=1,
  70                       bias_attr=False),
  71         )
  72         self.proj_head = ProjectionHead(dim_in=in_channels,
  73                                         proj_dim=self.proj_dim)
  74 
  75     def init_weight(self):
  76         if self.pretrained is not None:
  77             utils.load_entire_model(self, self.pretrained)
  78 
  79     def forward(self, x):
  80         feats = self.backbone(x)[0]
  81         out = self.cls_head(feats)
  82         logit_list = []
  83         if self.training:
  84             emb = self.proj_head(feats)
  85             logit_list.append(
  86                 F.interpolate(out,
  87                               paddle.shape(x)[2:],
  88                               mode='bilinear',
  89                               align_corners=self.align_corners))
  90             logit_list.append({'seg': out, 'embed': emb})
  91         else:
  92             logit_list.append(
  93                 F.interpolate(out,
  94                               paddle.shape(x)[2:],
  95                               mode='bilinear',
  96                               align_corners=self.align_corners))
  97         return logit_list
  98 
  99 
  100 class ProjectionHead(nn.Layer):
  101     """
  102     The projection head used by contrast learning.
  103     Args:
  104         dim_in (int): The dimensions of input features.
  105         proj_dim (int, optional): The output dimensions of projection head. Default: 256.
  106         proj (str, optional): The type of projection head, only support 'linear' and 'convmlp'. Default: 'convmlp'.
  107     """
  108     def __init__(self, dim_in, proj_dim=256, proj='convmlp'):
  109         super(ProjectionHead, self).__init__()
  110         if proj == 'linear':
  111             self.proj = nn.Conv2D(dim_in, proj_dim, kernel_size=1)
  112         elif proj == 'convmlp':
  113             self.proj = nn.Sequential(
  114                 layers.ConvBNReLU(dim_in, dim_in, kernel_size=1),
  115                 nn.Conv2D(dim_in, proj_dim, kernel_size=1),
  116             )
  117         else:
  118             raise ValueError(
  119                 "The type of project head only support 'linear' and 'convmlp', but got {}."
  120                 .format(proj))
  121 
  122     def forward(self, x):
  123         return F.normalize(self.proj(x), p=2, axis=1)
  124
  [end of paddleseg/models/hrnet_contrast.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/paddleseg/models/hrnet_contrast.py b/paddleseg/models/hrnet_contrast.py
  --- a/paddleseg/models/hrnet_contrast.py
  +++ b/paddleseg/models/hrnet_contrast.py
  @@ -40,6 +40,7 @@
               e.g. 1024x512, otherwise it is True, e.g. 769x769. Default: False.
           pretrained (str, optional): The path or url of pretrained model. Default: None.
       """
  +
       def __init__(self,
                    in_channels,
                    num_classes,
  @@ -54,23 +55,23 @@
           self.num_classes = num_classes
           self.proj_dim = proj_dim
           self.align_corners = align_corners
  -        self.pretrained = pretrained
   
           self.cls_head = nn.Sequential(
  -            layers.ConvBNReLU(in_channels,
  -                              in_channels,
  -                              kernel_size=3,
  -                              stride=1,
  -                              padding=1),
  +            layers.ConvBNReLU(
  +                in_channels, in_channels, kernel_size=3, stride=1, padding=1),
               nn.Dropout2D(drop_prob),
  -            nn.Conv2D(in_channels,
  -                      num_classes,
  -                      kernel_size=1,
  -                      stride=1,
  -                      bias_attr=False),
  +            nn.Conv2D(
  +                in_channels,
  +                num_classes,
  +                kernel_size=1,
  +                stride=1,
  +                bias_attr=False),
           )
  -        self.proj_head = ProjectionHead(dim_in=in_channels,
  -                                        proj_dim=self.proj_dim)
  +        self.proj_head = ProjectionHead(
  +            dim_in=in_channels, proj_dim=self.proj_dim)
  +
  +        self.pretrained = pretrained
  +        self.init_weight()
   
       def init_weight(self):
           if self.pretrained is not None:
  @@ -83,17 +84,19 @@
           if self.training:
               emb = self.proj_head(feats)
               logit_list.append(
  -                F.interpolate(out,
  -                              paddle.shape(x)[2:],
  -                              mode='bilinear',
  -                              align_corners=self.align_corners))
  +                F.interpolate(
  +                    out,
  +                    paddle.shape(x)[2:],
  +                    mode='bilinear',
  +                    align_corners=self.align_corners))
               logit_list.append({'seg': out, 'embed': emb})
           else:
               logit_list.append(
  -                F.interpolate(out,
  -                              paddle.shape(x)[2:],
  -                              mode='bilinear',
  -                              align_corners=self.align_corners))
  +                F.interpolate(
  +                    out,
  +                    paddle.shape(x)[2:],
  +                    mode='bilinear',
  +                    align_corners=self.align_corners))
           return logit_list
   
   
  @@ -105,6 +108,7 @@
           proj_dim (int, optional): The output dimensions of projection head. Default: 256.
           proj (str, optional): The type of projection head, only support 'linear' and 'convmlp'. Default: 'convmlp'.
       """
  +
       def __init__(self, dim_in, proj_dim=256, proj='convmlp'):
           super(ProjectionHead, self).__init__()
           if proj == 'linear':
  
verification_info: {"golden_diff": "diff --git a/paddleseg/models/hrnet_contrast.py b/paddleseg/models/hrnet_contrast.py\n--- a/paddleseg/models/hrnet_contrast.py\n+++ b/paddleseg/models/hrnet_contrast.py\n@@ -40,6 +40,7 @@\n             e.g. 1024x512, otherwise it is True, e.g. 769x769. Default: False.\n         pretrained (str, optional): The path or url of pretrained model. Default: None.\n     \"\"\"\n+\n     def __init__(self,\n                  in_channels,\n                  num_classes,\n@@ -54,23 +55,23 @@\n         self.num_classes = num_classes\n         self.proj_dim = proj_dim\n         self.align_corners = align_corners\n-        self.pretrained = pretrained\n \n         self.cls_head = nn.Sequential(\n-            layers.ConvBNReLU(in_channels,\n-                              in_channels,\n-                              kernel_size=3,\n-                              stride=1,\n-                              padding=1),\n+            layers.ConvBNReLU(\n+                in_channels, in_channels, kernel_size=3, stride=1, padding=1),\n             nn.Dropout2D(drop_prob),\n-            nn.Conv2D(in_channels,\n-                      num_classes,\n-                      kernel_size=1,\n-                      stride=1,\n-                      bias_attr=False),\n+            nn.Conv2D(\n+                in_channels,\n+                num_classes,\n+                kernel_size=1,\n+                stride=1,\n+                bias_attr=False),\n         )\n-        self.proj_head = ProjectionHead(dim_in=in_channels,\n-                                        proj_dim=self.proj_dim)\n+        self.proj_head = ProjectionHead(\n+            dim_in=in_channels, proj_dim=self.proj_dim)\n+\n+        self.pretrained = pretrained\n+        self.init_weight()\n \n     def init_weight(self):\n         if self.pretrained is not None:\n@@ -83,17 +84,19 @@\n         if self.training:\n             emb = self.proj_head(feats)\n             logit_list.append(\n-                F.interpolate(out,\n-                              paddle.shape(x)[2:],\n-                              mode='bilinear',\n-                              align_corners=self.align_corners))\n+                F.interpolate(\n+                    out,\n+                    paddle.shape(x)[2:],\n+                    mode='bilinear',\n+                    align_corners=self.align_corners))\n             logit_list.append({'seg': out, 'embed': emb})\n         else:\n             logit_list.append(\n-                F.interpolate(out,\n-                              paddle.shape(x)[2:],\n-                              mode='bilinear',\n-                              align_corners=self.align_corners))\n+                F.interpolate(\n+                    out,\n+                    paddle.shape(x)[2:],\n+                    mode='bilinear',\n+                    align_corners=self.align_corners))\n         return logit_list\n \n \n@@ -105,6 +108,7 @@\n         proj_dim (int, optional): The output dimensions of projection head. Default: 256.\n         proj (str, optional): The type of projection head, only support 'linear' and 'convmlp'. Default: 'convmlp'.\n     \"\"\"\n+\n     def __init__(self, dim_in, proj_dim=256, proj='convmlp'):\n         super(ProjectionHead, self).__init__()\n         if proj == 'linear':\n", "issue": "paddleseg/models/hrnet_contrast.py \u4e2d\u6ca1\u6709\u6267\u884c init_weight\npaddleseg/models/hrnet_contrast.py \u4e2d__init__()\u6ca1\u6709\u6267\u884c init_weight\uff0c\u5bfc\u81f4hrnet_w48_contrast \u6ca1\u6cd5\u52a0\u8f7d\u5b8c\u6574\u7684\u6a21\u578b\n", "before_files": [{"content": "# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport paddle\nimport paddle.nn as nn\nimport paddle.nn.functional as F\n\nfrom paddleseg.cvlibs import manager\nfrom paddleseg.models import layers\nfrom paddleseg.utils import utils\n\n\n@manager.MODELS.add_component\nclass HRNetW48Contrast(nn.Layer):\n    \"\"\"\n    The HRNetW48Contrast implementation based on PaddlePaddle.\n\n    The original article refers to\n    Wenguan Wang, Tianfei Zhou, et al. \"Exploring Cross-Image Pixel Contrast for Semantic Segmentation\"\n    (https://arxiv.org/abs/2101.11939).\n\n    Args:\n        in_channels (int): The output dimensions of backbone.\n        num_classes (int): The unique number of target classes.\n        backbone (Paddle.nn.Layer): Backbone network, currently support HRNet_W48.\n        drop_prob (float): The probability of dropout.\n        proj_dim (int): The projection dimensions.\n        align_corners (bool, optional): An argument of F.interpolate. It should be set to False when the feature size is even,\n            e.g. 1024x512, otherwise it is True, e.g. 769x769. Default: False.\n        pretrained (str, optional): The path or url of pretrained model. Default: None.\n    \"\"\"\n    def __init__(self,\n                 in_channels,\n                 num_classes,\n                 backbone,\n                 drop_prob,\n                 proj_dim,\n                 align_corners=False,\n                 pretrained=None):\n        super().__init__()\n        self.in_channels = in_channels\n        self.backbone = backbone\n        self.num_classes = num_classes\n        self.proj_dim = proj_dim\n        self.align_corners = align_corners\n        self.pretrained = pretrained\n\n        self.cls_head = nn.Sequential(\n            layers.ConvBNReLU(in_channels,\n                              in_channels,\n                              kernel_size=3,\n                              stride=1,\n                              padding=1),\n            nn.Dropout2D(drop_prob),\n            nn.Conv2D(in_channels,\n                      num_classes,\n                      kernel_size=1,\n                      stride=1,\n                      bias_attr=False),\n        )\n        self.proj_head = ProjectionHead(dim_in=in_channels,\n                                        proj_dim=self.proj_dim)\n\n    def init_weight(self):\n        if self.pretrained is not None:\n            utils.load_entire_model(self, self.pretrained)\n\n    def forward(self, x):\n        feats = self.backbone(x)[0]\n        out = self.cls_head(feats)\n        logit_list = []\n        if self.training:\n            emb = self.proj_head(feats)\n            logit_list.append(\n                F.interpolate(out,\n                              paddle.shape(x)[2:],\n                              mode='bilinear',\n                              align_corners=self.align_corners))\n            logit_list.append({'seg': out, 'embed': emb})\n        else:\n            logit_list.append(\n                F.interpolate(out,\n                              paddle.shape(x)[2:],\n                              mode='bilinear',\n                              align_corners=self.align_corners))\n        return logit_list\n\n\nclass ProjectionHead(nn.Layer):\n    \"\"\"\n    The projection head used by contrast learning.\n    Args:\n        dim_in (int): The dimensions of input features.\n        proj_dim (int, optional): The output dimensions of projection head. Default: 256.\n        proj (str, optional): The type of projection head, only support 'linear' and 'convmlp'. Default: 'convmlp'.\n    \"\"\"\n    def __init__(self, dim_in, proj_dim=256, proj='convmlp'):\n        super(ProjectionHead, self).__init__()\n        if proj == 'linear':\n            self.proj = nn.Conv2D(dim_in, proj_dim, kernel_size=1)\n        elif proj == 'convmlp':\n            self.proj = nn.Sequential(\n                layers.ConvBNReLU(dim_in, dim_in, kernel_size=1),\n                nn.Conv2D(dim_in, proj_dim, kernel_size=1),\n            )\n        else:\n            raise ValueError(\n                \"The type of project head only support 'linear' and 'convmlp', but got {}.\"\n                .format(proj))\n\n    def forward(self, x):\n        return F.normalize(self.proj(x), p=2, axis=1)\n", "path": "paddleseg/models/hrnet_contrast.py"}]}