transforms.Lambda fails on class functions
See original GitHub issuetransforms.Lambda
appears to fail when a function that is passed to it is a class function:
import torchvision
class MyClass(object):
def my_transform(self, img):
return img
def my_transform(img):
return img
t = MyClass()
print('Pure function works')
torchvision.transforms.Lambda(my_transform)
print('Class function fails')
torchvision.transforms.Lambda(t.my_transform)
Output:
Pure function works
Class function fails
Traceback (most recent call last):
File "test_pytorch.py", line 17, in <module>
torchvision.transforms.Lambda(t.my_transform)
File "/braintree/home/qbilius/libs/miniconda3/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 279, in __init__
assert isinstance(lambd, types.LambdaType)
AssertionError
My understanding it that isinstance(lambd, types.LambdaType)
is not the best way to check if something is a function or not. Rather, callable
or __call__
should be used.
I could submit a quick PR if that seems like a good solution.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
AWS Lambda function errors in Java
This page describes how to view Lambda function invocation errors for the Java runtime using the Lambda console and the AWS CLI.
Read more >c# - AWS Firehose transform Lambda function throws ...
I'm at a loss as to why or where this error is occurring. I know the Lambda function is returning the correct response,...
Read more >How To Use Python Lambda Functions
The interpreter raises an error while parsing the code since assert is not a valid keyword in a lambda expression. Single Expression. In...
Read more >Create an ETL solution using AWS Step Functions ...
AWS Glue is a fully managed Extract, Transform and Load (ETL) service that makes ... Create another Lambda function named crawler-activity-fail which sends ......
Read more >December 13, 2018, 1:54pm
Apparently you are passing a tuple , while the method expects a PIL.Image . ... Lambda(lambda crops: torch.stack([transforms.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Glad that you can adopt a more simple solution 😃
Concerning lambdas, I think the idea is similar to pythonic lambda expressions:
More realistic example, can be found even in torchvision with ColorJitter, where lambdas allows to wrap a function with initialization:
I agree with you that this can look artificial.
Anyway, maybe maintainers could explain better. cc @fmassa .
PS: if you think that there is an answer to your question you can close the issue and reopen it if there’s still something missing.
Thanks for your kind help!