Lightning-Universe/lightning-flash

`ObjectDetectionData.from_images` raise an error

serabiasin opened this issue ยท 0 comments

๐Ÿ› Bug

after pass the datamodule into finetune, at the end of the epoch it throws an error message:

/opt/conda/lib/python3.7/site-packages/flash/core/data/utilities/classification.py in _strip(x)
     44 
     45 def _strip(x: str) -> str:
---> 46     return x.strip(", ")
     47 
     48 

AttributeError: 'int' object has no attribute 'strip'

To Reproduce

Code sample

datamodule snipset code was from documentation

from flash.image import ObjectDetectionData, ObjectDetector
from PIL import Image
import numpy as np
from flash import Trainer

datamodule = ObjectDetectionData.from_images(
    train_images=[
        Image.fromarray(np.random.randint(0, 255, (512, 512, 3), dtype="uint8")),
         Image.fromarray(np.random.randint(0, 255,(512, 512, 3), dtype="uint8")),
         Image.fromarray(np.random.randint(0, 255, (512, 512, 3), dtype="uint8")),
    ],
         train_targets=[["cat"], ["cat"], ["cat"]],
     train_bboxes=[
         [{"xmin": 10, "ymin": 20, "width": 5, "height": 10}],
         [{"xmin": 20, "ymin": 30, "width": 10, "height": 10}],
         [{"xmin": 10, "ymin": 20, "width": 5, "height": 25}],
     ],
     predict_images=[Image.fromarray(np.random.randint(0, 255, (512, 512, 3), dtype="uint8"))],
     transform_kwargs=dict(image_size=(512, 512)),
     batch_size=2,
 )

model=ObjectDetector(
                        head="efficientdet", 
                        backbone="d0",
                        image_size=512,
                        labels=datamodule.labels,

                    )

trainer = Trainer(max_epochs=20,accelerator="gpu")
trainer.finetune(model, datamodule=datamodule, strategy="freeze")

Expected behavior

It should not throw an error after the end of an epoch

Environment

  • OS (e.g., Linux): Ubuntu
  • Python version: 3.7.111
  • PyTorch/Lightning/Flash Version : pytorch-lightning==1.7.0, lightning-flash==0.8.0
  • GPU models and configuration: Quadro T2000, Cuda Version 11.4