Giter Site home page Giter Site logo

Comments (8)

ncullen93 avatar ncullen93 commented on July 20, 2024 8

That looks almost right to me. You might need it after ToTensor though since it works on torch.Tensor. The issue with a lot of the actual pytorch transforms is that they only work on PIL images or numpy arrays instead of torch tensors.

Here's an example:

from torchsample.transforms import *
import torch as th
x = th.zeros(3,256,256)
x[:,50:150,50:150] = 1
xr = Rotate(10)(x)
xs = Shear(0.1)(x)
xz = Zoom((0.6,0.9))(x)

Then try to plot those to see how they change:

import matplotlib.pyplot as plt
plt.imshow(x[0].numpy())
plt.show()
plt.imshow(xr[0].numpy())
plt.show()
plt.imshow(xs[0].numpy())
plt.show()
plt.imshow(xz[0].numpy())
plt.show()

Original:
image
Rotated:
image
Sheared:
image
Zoomed:
image

And of course you can combine all of these into one transform using torchsample.transforms.Affine or torchsample.transforms.AffineCompose.. You'll want to use one of those if you're doing more than one affine transform so that it only does a single interpolation!

The cool and unique thing here is that If you just want to generate the transformation matrix, you can do so:

x = torch.rand(3,256,256)
rotation_tform = Rotate(30, lazy=True)(x)
print(rotation_tform)
# 0.8856 -0.4644  0.0000
# 0.4644  0.8856  0.0000
# 0.0000  0.0000  1.0000
#[torch.FloatTensor of size 3x3]

from torchsample.

wangg12 avatar wangg12 commented on July 20, 2024

@ncullen93 So I need to put Rotate(30) after ToTensor? BTW, the docstring of Rotate about lazy seems wrong. https://github.com/ncullen93/torchsample/blob/master/torchsample/transforms/affine_transforms.py#L184

from torchsample.

ncullen93 avatar ncullen93 commented on July 20, 2024

correct. I believe all or nearly all of the torchsample transforms operate directly on torch tensors. Therefore, if you're reading images you should call ToTensor first before any of them. and correct, they're switched thanks. I'll fix it.

from torchsample.

wangg12 avatar wangg12 commented on July 20, 2024

@ncullen93 The fill_mode argument is not implemented?

from torchsample.

ncullen93 avatar ncullen93 commented on July 20, 2024

No it just fills with 0's. Are you looking for something specific? I can implement it pretty quickly, but it will slow things down a fraction.

from torchsample.

wangg12 avatar wangg12 commented on July 20, 2024

Is filling 0 a common practice?

from torchsample.

ncullen93 avatar ncullen93 commented on July 20, 2024

Yes if your data is normalized to 0-1 or some constant otherwise. It's what I use

from torchsample.

wangg12 avatar wangg12 commented on July 20, 2024

OK, Thanks.

from torchsample.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.