prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  `Img2VecEncoder` calls `self.prepare` twice
  ## Your Environment
  * Python version: Python 3.8.10
  * Operating system: Ubuntu 20.04.3 LTS
  * Lightwood version: 1.3.0
  
  ## Describe your issue
  `Img2VecEncoder` crashes when `.encode(images)` is called.
  
  Internally there seems to be some confusion on what the `.prepare` method actually does.
  For some reason it is called to convert images to tensors, while in reality it should be used to initialize the model and (maybe) perform some initial training.
  
  ## Fixing the issue
  
  Implement a method to convert images to torch tensors.
  
  
  </issue>
  <code>
  [start of lightwood/encoder/image/img_2_vec.py]
  1 import logging
  2 import torch
  3 import torchvision.transforms as transforms
  4 from lightwood.encoder.image.helpers.img_to_vec import Img2Vec
  5 from lightwood.encoder.base import BaseEncoder
  6 
  7 
  8 class Img2VecEncoder(BaseEncoder):
  9 
  10     def __init__(self, is_target: bool = False):
  11         super().__init__(is_target)
  12         self.model = None
  13         # I think we should make this an enum, something like: speed, balance, accuracy
  14         self.aim = aim
  15         self._prepared = False
  16 
  17         self._scaler = transforms.Scale((224, 224))
  18         self._normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
  19         self._to_tensor = transforms.ToTensor()
  20 
  21         pil_logger = logging.getLogger('PIL')
  22         pil_logger.setLevel(logging.ERROR)
  23 
  24     def prepare(self, priming_data):
  25         if self._prepared:
  26             raise Exception('You can only call "prepare" once for a given encoder.')
  27 
  28         if self.model is None:
  29             self.model = Img2Vec(model='resnext-50-small')
  30         self._prepared = True
  31 
  32     def encode(self, images):
  33         """
  34             Encode list of images
  35 
  36             :images : list of images, each image is a path to a file or a url
  37             :return: a torch.floatTensor
  38         """
  39         if not self._prepared:
  40             raise Exception('You need to call "prepare" before calling "encode" or "decode".')
  41 
  42         img_tensors = self.prepare(images)
  43         vec_arr = []
  44         self.model.eval()
  45         with torch.no_grad():
  46             for img_tensor in img_tensors:
  47                 vec = self.model(img_tensor.unsqueeze(0), batch=False)
  48                 vec_arr.append(vec)
  49         return torch.stack(vec_arr)
  50 
  51     def decode(self, encoded_values_tensor):
  52         raise Exception('This encoder is not bi-directional')
  53
  [end of lightwood/encoder/image/img_2_vec.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/lightwood/encoder/image/img_2_vec.py b/lightwood/encoder/image/img_2_vec.py
  --- a/lightwood/encoder/image/img_2_vec.py
  +++ b/lightwood/encoder/image/img_2_vec.py
  @@ -3,6 +3,7 @@
   import torchvision.transforms as transforms
   from lightwood.encoder.image.helpers.img_to_vec import Img2Vec
   from lightwood.encoder.base import BaseEncoder
  +from PIL import Image
   
   
   class Img2VecEncoder(BaseEncoder):
  @@ -10,13 +11,18 @@
       def __init__(self, is_target: bool = False):
           super().__init__(is_target)
           self.model = None
  -        # I think we should make this an enum, something like: speed, balance, accuracy
  -        self.aim = aim
  +        # # I think we should make this an enum, something like: speed, balance, accuracy
  +        # self.aim = aim
           self._prepared = False
   
  -        self._scaler = transforms.Scale((224, 224))
  +        self._scaler = transforms.Resize((224, 224))
           self._normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
           self._to_tensor = transforms.ToTensor()
  +        self._img_to_tensor = transforms.Compose([
  +            self._scaler,
  +            self._to_tensor,
  +            self._normalize
  +        ])
   
           pil_logger = logging.getLogger('PIL')
           pil_logger.setLevel(logging.ERROR)
  @@ -39,8 +45,11 @@
           if not self._prepared:
               raise Exception('You need to call "prepare" before calling "encode" or "decode".')
   
  -        img_tensors = self.prepare(images)
  +        img_tensors = [self._img_to_tensor(
  +            Image.open(img_path)
  +        ) for img_path in images]
           vec_arr = []
  +
           self.model.eval()
           with torch.no_grad():
               for img_tensor in img_tensors:
  
verification_info: {"golden_diff": "diff --git a/lightwood/encoder/image/img_2_vec.py b/lightwood/encoder/image/img_2_vec.py\n--- a/lightwood/encoder/image/img_2_vec.py\n+++ b/lightwood/encoder/image/img_2_vec.py\n@@ -3,6 +3,7 @@\n import torchvision.transforms as transforms\n from lightwood.encoder.image.helpers.img_to_vec import Img2Vec\n from lightwood.encoder.base import BaseEncoder\n+from PIL import Image\n \n \n class Img2VecEncoder(BaseEncoder):\n@@ -10,13 +11,18 @@\n     def __init__(self, is_target: bool = False):\n         super().__init__(is_target)\n         self.model = None\n-        # I think we should make this an enum, something like: speed, balance, accuracy\n-        self.aim = aim\n+        # # I think we should make this an enum, something like: speed, balance, accuracy\n+        # self.aim = aim\n         self._prepared = False\n \n-        self._scaler = transforms.Scale((224, 224))\n+        self._scaler = transforms.Resize((224, 224))\n         self._normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])\n         self._to_tensor = transforms.ToTensor()\n+        self._img_to_tensor = transforms.Compose([\n+            self._scaler,\n+            self._to_tensor,\n+            self._normalize\n+        ])\n \n         pil_logger = logging.getLogger('PIL')\n         pil_logger.setLevel(logging.ERROR)\n@@ -39,8 +45,11 @@\n         if not self._prepared:\n             raise Exception('You need to call \"prepare\" before calling \"encode\" or \"decode\".')\n \n-        img_tensors = self.prepare(images)\n+        img_tensors = [self._img_to_tensor(\n+            Image.open(img_path)\n+        ) for img_path in images]\n         vec_arr = []\n+\n         self.model.eval()\n         with torch.no_grad():\n             for img_tensor in img_tensors:\n", "issue": "`Img2VecEncoder` calls `self.prepare` twice\n## Your Environment\r\n* Python version: Python 3.8.10\r\n* Operating system: Ubuntu 20.04.3 LTS\r\n* Lightwood version: 1.3.0\r\n\r\n## Describe your issue\r\n`Img2VecEncoder` crashes when `.encode(images)` is called.\r\n\r\nInternally there seems to be some confusion on what the `.prepare` method actually does.\r\nFor some reason it is called to convert images to tensors, while in reality it should be used to initialize the model and (maybe) perform some initial training.\r\n\r\n## Fixing the issue\r\n\r\nImplement a method to convert images to torch tensors.\r\n\n", "before_files": [{"content": "import logging\nimport torch\nimport torchvision.transforms as transforms\nfrom lightwood.encoder.image.helpers.img_to_vec import Img2Vec\nfrom lightwood.encoder.base import BaseEncoder\n\n\nclass Img2VecEncoder(BaseEncoder):\n\n    def __init__(self, is_target: bool = False):\n        super().__init__(is_target)\n        self.model = None\n        # I think we should make this an enum, something like: speed, balance, accuracy\n        self.aim = aim\n        self._prepared = False\n\n        self._scaler = transforms.Scale((224, 224))\n        self._normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])\n        self._to_tensor = transforms.ToTensor()\n\n        pil_logger = logging.getLogger('PIL')\n        pil_logger.setLevel(logging.ERROR)\n\n    def prepare(self, priming_data):\n        if self._prepared:\n            raise Exception('You can only call \"prepare\" once for a given encoder.')\n\n        if self.model is None:\n            self.model = Img2Vec(model='resnext-50-small')\n        self._prepared = True\n\n    def encode(self, images):\n        \"\"\"\n            Encode list of images\n\n            :images : list of images, each image is a path to a file or a url\n            :return: a torch.floatTensor\n        \"\"\"\n        if not self._prepared:\n            raise Exception('You need to call \"prepare\" before calling \"encode\" or \"decode\".')\n\n        img_tensors = self.prepare(images)\n        vec_arr = []\n        self.model.eval()\n        with torch.no_grad():\n            for img_tensor in img_tensors:\n                vec = self.model(img_tensor.unsqueeze(0), batch=False)\n                vec_arr.append(vec)\n        return torch.stack(vec_arr)\n\n    def decode(self, encoded_values_tensor):\n        raise Exception('This encoder is not bi-directional')\n", "path": "lightwood/encoder/image/img_2_vec.py"}]}