prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Hub Detr fine tuning
  Following the first relase of Detr on hub, it would be a very good idea to support fine tuning.
  
  [this](https://github.com/facebookresearch/detr/issues/9) thread should be helpful, and [this](https://gist.github.com/mlk1337/651297e28199b4bb7907fc413c49f58f) gist has the high level overview on how to implement it.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `examples/detr_wheat.py`
  Content:
  ```
  1 import pandas as pd
  2 from mantisshrimp.imports import *
  3 from mantisshrimp.hub.detr import *
  4 
  5 
  6 class WheatParser(DetrBBoxParser):
  7     def __init__(self, df, source):
  8         self.df = df
  9         self.source = source
  10         self.imageid_map = IDMap()
  11 
  12     def __iter__(self):
  13         yield from self.df.itertuples()
  14 
  15     def __len__(self):
  16         return len(self.df)
  17 
  18     def prepare(self, o):
  19         self.bbox = BBox.from_xywh(*np.fromstring(o.bbox[1:-1], sep=","))
  20 
  21     def imageid(self, o) -> int:
  22         return self.imageid_map[o.image_id]
  23 
  24     def filepath(self, o) -> Union[str, Path]:
  25         return self.source / f"{o.image_id}.jpg"
  26 
  27     def height(self, o) -> int:
  28         return o.height
  29 
  30     def width(self, o) -> int:
  31         return o.width
  32 
  33     def label(self, o) -> int:
  34         return 1
  35 
  36     def bbox(self, o) -> BBox:
  37         return self.bbox
  38 
  39     def area(self, o) -> float:
  40         return self.bbox.area
  41 
  42     def iscrowd(self, o) -> bool:
  43         return 0
  44 
  45 
  46 def get_datasets(args):
  47     # parse records
  48     source = Path(args.data_path)
  49     df = pd.read_csv(source / "train.csv")
  50     data_splitter = RandomSplitter([0.8, 0.2])
  51     parser = WheatParser(df, source / "train")
  52     train_rs, valid_rs = parser.parse(data_splitter)
  53     # We use the transforms defined by the authors
  54     train_tfm = detr_transform("train")
  55     valid_tfm = detr_transform("val")
  56     train_dataset = DetrDataset(train_rs, train_tfm)
  57     valid_dataset = DetrDataset(valid_rs, valid_tfm)
  58     return train_dataset, valid_dataset
  59 
  60 
  61 if __name__ == "__main__":
  62     # adds new arguments to original args_parser
  63     args_parser = get_args_parser()
  64     args_parser.add_argument("--data_path", type=str)
  65     args = args_parser.parse_args()
  66 
  67     train_dataset, valid_dataset = get_datasets(args)
  68     run_detr(args=args, dataset_train=train_dataset, dataset_val=valid_dataset)
  69
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/examples/detr_wheat.py b/examples/detr_wheat.py
  --- a/examples/detr_wheat.py
  +++ b/examples/detr_wheat.py
  @@ -30,17 +30,17 @@
       def width(self, o) -> int:
           return o.width
   
  -    def label(self, o) -> int:
  -        return 1
  +    def label(self, o) -> List[int]:
  +        return [1]
   
  -    def bbox(self, o) -> BBox:
  -        return self.bbox
  +    def bbox(self, o) -> List[BBox]:
  +        return [self.bbox]
   
  -    def area(self, o) -> float:
  -        return self.bbox.area
  +    def area(self, o) -> List[float]:
  +        return [self.bbox.area]
   
  -    def iscrowd(self, o) -> bool:
  -        return 0
  +    def iscrowd(self, o) -> List[bool]:
  +        return [0]
   
   
   def get_datasets(args):
  @@ -62,7 +62,12 @@
       # adds new arguments to original args_parser
       args_parser = get_args_parser()
       args_parser.add_argument("--data_path", type=str)
  +    args_parser.add_argument("--num_classes", type=int, default=None)
  +    args_parser.add_argument("--fine_tune", action="store_true")
       args = args_parser.parse_args()
   
  +    if args.fine_tune:
  +        args.resume = detr_pretrained_checkpoint_base()
  +
       train_dataset, valid_dataset = get_datasets(args)
       run_detr(args=args, dataset_train=train_dataset, dataset_val=valid_dataset)
  
verification_info: {"golden_diff": "diff --git a/examples/detr_wheat.py b/examples/detr_wheat.py\n--- a/examples/detr_wheat.py\n+++ b/examples/detr_wheat.py\n@@ -30,17 +30,17 @@\n     def width(self, o) -> int:\n         return o.width\n \n-    def label(self, o) -> int:\n-        return 1\n+    def label(self, o) -> List[int]:\n+        return [1]\n \n-    def bbox(self, o) -> BBox:\n-        return self.bbox\n+    def bbox(self, o) -> List[BBox]:\n+        return [self.bbox]\n \n-    def area(self, o) -> float:\n-        return self.bbox.area\n+    def area(self, o) -> List[float]:\n+        return [self.bbox.area]\n \n-    def iscrowd(self, o) -> bool:\n-        return 0\n+    def iscrowd(self, o) -> List[bool]:\n+        return [0]\n \n \n def get_datasets(args):\n@@ -62,7 +62,12 @@\n     # adds new arguments to original args_parser\n     args_parser = get_args_parser()\n     args_parser.add_argument(\"--data_path\", type=str)\n+    args_parser.add_argument(\"--num_classes\", type=int, default=None)\n+    args_parser.add_argument(\"--fine_tune\", action=\"store_true\")\n     args = args_parser.parse_args()\n \n+    if args.fine_tune:\n+        args.resume = detr_pretrained_checkpoint_base()\n+\n     train_dataset, valid_dataset = get_datasets(args)\n     run_detr(args=args, dataset_train=train_dataset, dataset_val=valid_dataset)\n", "issue": "Hub Detr fine tuning\nFollowing the first relase of Detr on hub, it would be a very good idea to support fine tuning.\r\n\r\n[this](https://github.com/facebookresearch/detr/issues/9) thread should be helpful, and [this](https://gist.github.com/mlk1337/651297e28199b4bb7907fc413c49f58f) gist has the high level overview on how to implement it.\n", "before_files": [{"content": "import pandas as pd\nfrom mantisshrimp.imports import *\nfrom mantisshrimp.hub.detr import *\n\n\nclass WheatParser(DetrBBoxParser):\n    def __init__(self, df, source):\n        self.df = df\n        self.source = source\n        self.imageid_map = IDMap()\n\n    def __iter__(self):\n        yield from self.df.itertuples()\n\n    def __len__(self):\n        return len(self.df)\n\n    def prepare(self, o):\n        self.bbox = BBox.from_xywh(*np.fromstring(o.bbox[1:-1], sep=\",\"))\n\n    def imageid(self, o) -> int:\n        return self.imageid_map[o.image_id]\n\n    def filepath(self, o) -> Union[str, Path]:\n        return self.source / f\"{o.image_id}.jpg\"\n\n    def height(self, o) -> int:\n        return o.height\n\n    def width(self, o) -> int:\n        return o.width\n\n    def label(self, o) -> int:\n        return 1\n\n    def bbox(self, o) -> BBox:\n        return self.bbox\n\n    def area(self, o) -> float:\n        return self.bbox.area\n\n    def iscrowd(self, o) -> bool:\n        return 0\n\n\ndef get_datasets(args):\n    # parse records\n    source = Path(args.data_path)\n    df = pd.read_csv(source / \"train.csv\")\n    data_splitter = RandomSplitter([0.8, 0.2])\n    parser = WheatParser(df, source / \"train\")\n    train_rs, valid_rs = parser.parse(data_splitter)\n    # We use the transforms defined by the authors\n    train_tfm = detr_transform(\"train\")\n    valid_tfm = detr_transform(\"val\")\n    train_dataset = DetrDataset(train_rs, train_tfm)\n    valid_dataset = DetrDataset(valid_rs, valid_tfm)\n    return train_dataset, valid_dataset\n\n\nif __name__ == \"__main__\":\n    # adds new arguments to original args_parser\n    args_parser = get_args_parser()\n    args_parser.add_argument(\"--data_path\", type=str)\n    args = args_parser.parse_args()\n\n    train_dataset, valid_dataset = get_datasets(args)\n    run_detr(args=args, dataset_train=train_dataset, dataset_val=valid_dataset)\n", "path": "examples/detr_wheat.py"}], "after_files": [{"content": "import pandas as pd\nfrom mantisshrimp.imports import *\nfrom mantisshrimp.hub.detr import *\n\n\nclass WheatParser(DetrBBoxParser):\n    def __init__(self, df, source):\n        self.df = df\n        self.source = source\n        self.imageid_map = IDMap()\n\n    def __iter__(self):\n        yield from self.df.itertuples()\n\n    def __len__(self):\n        return len(self.df)\n\n    def prepare(self, o):\n        self.bbox = BBox.from_xywh(*np.fromstring(o.bbox[1:-1], sep=\",\"))\n\n    def imageid(self, o) -> int:\n        return self.imageid_map[o.image_id]\n\n    def filepath(self, o) -> Union[str, Path]:\n        return self.source / f\"{o.image_id}.jpg\"\n\n    def height(self, o) -> int:\n        return o.height\n\n    def width(self, o) -> int:\n        return o.width\n\n    def label(self, o) -> List[int]:\n        return [1]\n\n    def bbox(self, o) -> List[BBox]:\n        return [self.bbox]\n\n    def area(self, o) -> List[float]:\n        return [self.bbox.area]\n\n    def iscrowd(self, o) -> List[bool]:\n        return [0]\n\n\ndef get_datasets(args):\n    # parse records\n    source = Path(args.data_path)\n    df = pd.read_csv(source / \"train.csv\")\n    data_splitter = RandomSplitter([0.8, 0.2])\n    parser = WheatParser(df, source / \"train\")\n    train_rs, valid_rs = parser.parse(data_splitter)\n    # We use the transforms defined by the authors\n    train_tfm = detr_transform(\"train\")\n    valid_tfm = detr_transform(\"val\")\n    train_dataset = DetrDataset(train_rs, train_tfm)\n    valid_dataset = DetrDataset(valid_rs, valid_tfm)\n    return train_dataset, valid_dataset\n\n\nif __name__ == \"__main__\":\n    # adds new arguments to original args_parser\n    args_parser = get_args_parser()\n    args_parser.add_argument(\"--data_path\", type=str)\n    args_parser.add_argument(\"--num_classes\", type=int, default=None)\n    args_parser.add_argument(\"--fine_tune\", action=\"store_true\")\n    args = args_parser.parse_args()\n\n    if args.fine_tune:\n        args.resume = detr_pretrained_checkpoint_base()\n\n    train_dataset, valid_dataset = get_datasets(args)\n    run_detr(args=args, dataset_train=train_dataset, dataset_val=valid_dataset)\n", "path": "examples/detr_wheat.py"}]}