Comments (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:
Rotated:
Sheared:
Zoomed:
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.
@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.
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.
@ncullen93 The fill_mode
argument is not implemented?
from torchsample.
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.
Is filling 0 a common practice?
from torchsample.
Yes if your data is normalized to 0-1 or some constant otherwise. It's what I use
from torchsample.
OK, Thanks.
from torchsample.
Related Issues (20)
- Binary Classification not working HOT 1
- Using Pre-Trained models
- How to set the learning rate for the optimizer in the ModuleTrainer compile function
- Are there any tutorials and documents for this repo? HOT 1
- How can I use torchsample with vae
- Range Normalization divide by 0?
- is this still under development?
- Pytorch1.3 upgradations welcome??
- Callbacks.ReduceLROnPlateau seems not work for small learning rate
- Can torchsample augment 3D medical image directly? HOT 1
- callback with input data (and targets)
- AlphaPose Project for python don't run on my windows10 (2020)
- Contact HOT 1
- Installing torchsample and ModuleTrainer
- customized loss function HOT 1
- Index error in module_trainer.py HOT 1
- Missing data type conversion for interpolation
- Support for torch Variables
- pip3 install
- Binary Classification Accuracy calculation error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torchsample.