question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: __init__() got an unexpected keyword argument 'transform'

See original GitHub issue

🐛 Bug

Uncaught exception
Traceback (most recent call last):
  File "/mnt/data/buduanban_detection/meteo.py", line 103, in <module>
    datamodule = ObjectDetectionData.from_coco(
  File "/data/miniconda3/envs/torch/lib/python3.9/site-packages/flash/image/detection/data.py", line 386, in from_coco
    return cls.from_icedata(
  File "/data/miniconda3/envs/torch/lib/python3.9/site-packages/flash/image/detection/data.py", line 220, in from_icedata
    return cls(
TypeError: __init__() got an unexpected keyword argument 'transform'

To Reproduce

The code is directly copied from https://lightning-flash.readthedocs.io/en/latest/reference/object_detection.html

Code sample

from dataclasses import dataclass
import albumentations as alb
from icevision.tfms import A

from flash import InputTransform
from flash.core.integrations.icevision.transforms import IceVisionTransformAdapter
from flash.image import ObjectDetectionData


@dataclass
class BrightnessContrastTransform(InputTransform):
    image_size: int = 128

    def per_sample_transform(self):
        return IceVisionTransformAdapter(
            [*A.aug_tfms(size=self.image_size), A.Normalize(), alb.RandomBrightnessContrast()]
        )


datamodule = ObjectDetectionData.from_coco(
    train_folder="data/coco128/images/train2017/",
    train_ann_file="data/coco128/annotations/instances_train2017.json",
    val_split=0.1,
    transform=BrightnessContrastTransform,
    batch_size=4,
)

Expected behavior

Environment

  • OS (e.g., Linux):
  • Python version:
  • PyTorch/Lightning/Flash Version (e.g., 1.10/1.5/0.7):
  • GPU models and configuration:
  • Any other relevant information:

Additional context

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ligazcommented, Mar 28, 2022

There is a breaking change in the latest version of flash that unifies all transforms in a single API implemented in https://github.com/PyTorchLightning/lightning-flash/pull/1233. Please refer to the 0.7.1 version of the docs in order to make this work - https://lightning-flash.readthedocs.io/en/0.7.1/reference/object_detection.html

In your particular case you should use train_transform instead of transform (the new API) in ObjectDetectionData.from_coco call.

1reaction
IncubatorShokuhoucommented, Mar 28, 2022

There is a breaking change in the latest version of flash that unifies all transforms in a single API implemented in #1233. Please refer to the 0.7.1 version of the docs in order to make this work - https://lightning-flash.readthedocs.io/en/0.7.1/reference/object_detection.html In your particular case you should use train_transform instead of transform (the new API) in ObjectDetectionData.from_coco call.

Thank you @ligaz , it works.

If you are happy with it, please feel free to close this issue 😃 Thank you for your patience. 😃

Thank you @krshrimali.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pytorch __init__() got an unexpected keyword argument 'train'
The error implies that it couldn't recognize the train parameter, in the ImageFolder class. ImageFolder() does not have a parameter train, ...
Read more >
TypeError: __init__() got an unexpected keyword argument ...
Another solution including the transformation of the X object in array type in a float64 type from sklearn ...
Read more >
TypeError: __init__() got an unexpected keyword ... - GitHub
and it give my a TypeError: init() got an unexpected keyword argument 'target_tensor' my python version is 2.7.15 and torch version is 0.4.0....
Read more >
init__() got an unexpected keyword argument 'max_iter'?
TypeError : init() got an unexpected keyword argument 'max_iter'. I m running the linear regression code in Community edition. Google says reinstall --....
Read more >
tensor.__init__() got an unexpected keyword argument 'shape'
Running the code above gives the error: TypeError: __init__ () got an unexpected keyword argument 'shape'. The comment below says that tf.zeros_initializer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found