prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ImageEmbedder default behavior is not a flattened output
  ## 🐛 Bug
  
  I discovered this issue while testing PR #655. If you run the [Image Embedding README example code](https://github.com/PyTorchLightning/lightning-flash#example-1-image-embedding), it returns a 3D tensor. 
  My understanding from the use of embeddings in general, and how they are used in [Fifty One](https://voxel51.com/docs/fiftyone/tutorials/image_embeddings.html) is they expect the embeddings to be 1D (for each embedding). 
  
  The reason it returns a 3D tensor is because it depends on the backbone used. The default there is `resnet101`, which returns a `2048x7x7` shape tensor. Others like inception return a flat 1D tensor, i.e. length-X.
  
  ### To Reproduce
  
  Steps to reproduce the behavior:
  
  Run the [README example](https://github.com/PyTorchLightning/lightning-flash#example-1-image-embedding), but remove the `embedding_dim` parameter. See below for example.
  
  Note: as-is, this will error on `print(embeddings.shape)`, regardless of configuration, since that is a list. But the question here is around the logic for the ImageEmbedder. 
  
  
  #### Code sample
  ```python
  from flash.core.data.utils import download_data
  from flash.image import ImageEmbedder
  
  # 1. Download the data
  download_data("https://pl-flash-data.s3.amazonaws.com/hymenoptera_data.zip", "data/")
  
  # 2. Create an ImageEmbedder with resnet50 trained on imagenet.
  embedder = ImageEmbedder(backbone="resnet50")
  
  # 3. Generate an embedding from an image path.
  embeddings = embedder.predict("data/hymenoptera_data/predict/153783656_85f9c3ac70.jpg")
  
  # 4. Print embeddings shape
  print(embeddings.shape)
  ```
  
  ### Expected behavior
  
  Expect to see a 100352x1 shape tensor as the output, instead of 2048x7x7. 
  
  ### Environment
  
   - PyTorch Version (e.g., 1.0): 1.9
   - OS (e.g., Linux): Linux
   - How you installed PyTorch (`conda`, `pip`, source): pip
   - Build command you used (if compiling from source): N/A
   - Python version: 3.8.6
   - CUDA/cuDNN version: N/A
   - GPU models and configuration: N/A
   - Any other relevant information: N/A
  
  ### Additional context
  
  I believe the question is around what the logic should be here:
  https://github.com/PyTorchLightning/lightning-flash/blob/075de3a46d74d9fc0e769401063fede1f12d0518/flash/image/embedding/model.py#L85-L92
  
  If `embedding_dim` is None, then the head is `nn.Identity()`. **If we desire a flat 1D embedding, then the question is: should `nn.Identity()` change to `nn.Flatten()`?**
  
  It could be argued that the user should be left to flatten after on their own, but per the contributing guidelines, I thought this would align with "[Force User Decisions To Best Practices](https://github.com/PyTorchLightning/lightning-flash/blob/ddd942d3dfe3884a97a855446410166c3c9f16d9/.github/CONTRIBUTING.md#force-user-decisions-to-best-practices)"
  
  Let me know your thoughts. If that makes sense, then I can update the code, run some tests, and update docs in a PR. 
  
  
  </issue>
  <code>
  [start of flash_examples/integrations/fiftyone/image_embedding.py]
  1 # Copyright The PyTorch Lightning team.
  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 import fiftyone as fo
  15 import fiftyone.brain as fob
  16 import numpy as np
  17 
  18 from flash.core.data.utils import download_data
  19 from flash.image import ImageEmbedder
  20 
  21 # 1 Download data
  22 download_data("https://pl-flash-data.s3.amazonaws.com/hymenoptera_data.zip")
  23 
  24 # 2 Load data into FiftyOne
  25 dataset = fo.Dataset.from_dir(
  26     "data/hymenoptera_data/test/",
  27     fo.types.ImageClassificationDirectoryTree,
  28 )
  29 
  30 # 3 Load model
  31 embedder = ImageEmbedder(backbone="resnet101", embedding_dim=128)
  32 
  33 # 4 Generate embeddings
  34 filepaths = dataset.values("filepath")
  35 embeddings = np.stack(embedder.predict(filepaths))
  36 
  37 # 5 Visualize in FiftyOne App
  38 results = fob.compute_visualization(dataset, embeddings=embeddings)
  39 session = fo.launch_app(dataset)
  40 plot = results.visualize(labels="ground_truth.label")
  41 plot.show()
  42 
  43 # Optional: block execution until App is closed
  44 session.wait()
  45
  [end of flash_examples/integrations/fiftyone/image_embedding.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/flash_examples/integrations/fiftyone/image_embedding.py b/flash_examples/integrations/fiftyone/image_embedding.py
  --- a/flash_examples/integrations/fiftyone/image_embedding.py
  +++ b/flash_examples/integrations/fiftyone/image_embedding.py
  @@ -28,7 +28,7 @@
   )
   
   # 3 Load model
  -embedder = ImageEmbedder(backbone="resnet101", embedding_dim=128)
  +embedder = ImageEmbedder(backbone="resnet101")
   
   # 4 Generate embeddings
   filepaths = dataset.values("filepath")
  
verification_info: {"golden_diff": "diff --git a/flash_examples/integrations/fiftyone/image_embedding.py b/flash_examples/integrations/fiftyone/image_embedding.py\n--- a/flash_examples/integrations/fiftyone/image_embedding.py\n+++ b/flash_examples/integrations/fiftyone/image_embedding.py\n@@ -28,7 +28,7 @@\n )\n \n # 3 Load model\n-embedder = ImageEmbedder(backbone=\"resnet101\", embedding_dim=128)\n+embedder = ImageEmbedder(backbone=\"resnet101\")\n \n # 4 Generate embeddings\n filepaths = dataset.values(\"filepath\")\n", "issue": "ImageEmbedder default behavior is not a flattened output\n## \ud83d\udc1b Bug\r\n\r\nI discovered this issue while testing PR #655. If you run the [Image Embedding README example code](https://github.com/PyTorchLightning/lightning-flash#example-1-image-embedding), it returns a 3D tensor. \r\nMy understanding from the use of embeddings in general, and how they are used in [Fifty One](https://voxel51.com/docs/fiftyone/tutorials/image_embeddings.html) is they expect the embeddings to be 1D (for each embedding). \r\n\r\nThe reason it returns a 3D tensor is because it depends on the backbone used. The default there is `resnet101`, which returns a `2048x7x7` shape tensor. Others like inception return a flat 1D tensor, i.e. length-X.\r\n\r\n### To Reproduce\r\n\r\nSteps to reproduce the behavior:\r\n\r\nRun the [README example](https://github.com/PyTorchLightning/lightning-flash#example-1-image-embedding), but remove the `embedding_dim` parameter. See below for example.\r\n\r\nNote: as-is, this will error on `print(embeddings.shape)`, regardless of configuration, since that is a list. But the question here is around the logic for the ImageEmbedder. \r\n\r\n\r\n#### Code sample\r\n```python\r\nfrom flash.core.data.utils import download_data\r\nfrom flash.image import ImageEmbedder\r\n\r\n# 1. Download the data\r\ndownload_data(\"https://pl-flash-data.s3.amazonaws.com/hymenoptera_data.zip\", \"data/\")\r\n\r\n# 2. Create an ImageEmbedder with resnet50 trained on imagenet.\r\nembedder = ImageEmbedder(backbone=\"resnet50\")\r\n\r\n# 3. Generate an embedding from an image path.\r\nembeddings = embedder.predict(\"data/hymenoptera_data/predict/153783656_85f9c3ac70.jpg\")\r\n\r\n# 4. Print embeddings shape\r\nprint(embeddings.shape)\r\n```\r\n\r\n### Expected behavior\r\n\r\nExpect to see a 100352x1 shape tensor as the output, instead of 2048x7x7. \r\n\r\n### Environment\r\n\r\n - PyTorch Version (e.g., 1.0): 1.9\r\n - OS (e.g., Linux): Linux\r\n - How you installed PyTorch (`conda`, `pip`, source): pip\r\n - Build command you used (if compiling from source): N/A\r\n - Python version: 3.8.6\r\n - CUDA/cuDNN version: N/A\r\n - GPU models and configuration: N/A\r\n - Any other relevant information: N/A\r\n\r\n### Additional context\r\n\r\nI believe the question is around what the logic should be here:\r\nhttps://github.com/PyTorchLightning/lightning-flash/blob/075de3a46d74d9fc0e769401063fede1f12d0518/flash/image/embedding/model.py#L85-L92\r\n\r\nIf `embedding_dim` is None, then the head is `nn.Identity()`. **If we desire a flat 1D embedding, then the question is: should `nn.Identity()` change to `nn.Flatten()`?**\r\n\r\nIt could be argued that the user should be left to flatten after on their own, but per the contributing guidelines, I thought this would align with \"[Force User Decisions To Best Practices](https://github.com/PyTorchLightning/lightning-flash/blob/ddd942d3dfe3884a97a855446410166c3c9f16d9/.github/CONTRIBUTING.md#force-user-decisions-to-best-practices)\"\r\n\r\nLet me know your thoughts. If that makes sense, then I can update the code, run some tests, and update docs in a PR. \r\n\n", "before_files": [{"content": "# Copyright The PyTorch Lightning team.\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.\nimport fiftyone as fo\nimport fiftyone.brain as fob\nimport numpy as np\n\nfrom flash.core.data.utils import download_data\nfrom flash.image import ImageEmbedder\n\n# 1 Download data\ndownload_data(\"https://pl-flash-data.s3.amazonaws.com/hymenoptera_data.zip\")\n\n# 2 Load data into FiftyOne\ndataset = fo.Dataset.from_dir(\n    \"data/hymenoptera_data/test/\",\n    fo.types.ImageClassificationDirectoryTree,\n)\n\n# 3 Load model\nembedder = ImageEmbedder(backbone=\"resnet101\", embedding_dim=128)\n\n# 4 Generate embeddings\nfilepaths = dataset.values(\"filepath\")\nembeddings = np.stack(embedder.predict(filepaths))\n\n# 5 Visualize in FiftyOne App\nresults = fob.compute_visualization(dataset, embeddings=embeddings)\nsession = fo.launch_app(dataset)\nplot = results.visualize(labels=\"ground_truth.label\")\nplot.show()\n\n# Optional: block execution until App is closed\nsession.wait()\n", "path": "flash_examples/integrations/fiftyone/image_embedding.py"}]}