Comments (2)
Here's a minimal code snippet for applying a pre-trained Spatial Transformer (non-clustering) to one image:
from models import get_stn
from utils.download import download_model
from utils.vis_tools.helpers import load_pil
from torchvision.utils import save_image
resolution = 512 # resolution the input image will be resized to (this can be any power of 2)
input_img = load_pil('my_image.png', resolution) # load the input image and resize to (1, C, resolution, resolution)
ckpt = download_model('cat') # download model weights
stn = get_stn(['similarity', 'flow'], flow_size=128, supersize=resolution).to('cuda') # instantiate STN
stn.load_state_dict(ckpt['t_ema']) # load weights
aligned_img = stn(input_img, iters=3, output_resolution=resolution) # forward pass through the STN
save_image(aligned_img, 'output.png', normalize=True, range=(-1, 1)) # save to disk
If you're using the celeba
or cub
models, use iters=1
instead. If your input image isn't square you may want to pad or crop it beforehand. Also, stn
supports batch mode, so input_img
can be an (N, C, H, W)
tensor containing multiple images, in which case aligned_image
will also be (N, C, H, W)
.
from gangealing.
thanks. : )
from gangealing.
Related Issues (20)
- error with fused_bias_act_kernel.cu HOT 2
- single color channel HOT 2
- No module named 'fused' HOT 4
- loss going up HOT 3
- RuntimeError: Error building extension '_splat' during visualization HOT 2
- add Gradio Web Demo to cvpr 2022 organization HOT 2
- get dense corresponded / tracking coordination HOT 5
- about StyleGan2 ADA training process HOT 4
- model synthesizes features to fool the loss HOT 10
- RuntimeError in colab HOT 2
- how to train LPIPS(Perceptual Losses) myself HOT 1
- Adding masks to the upper forehead/lower chin HOT 4
- Missing State Dict Keys for CelebA HOT 2
- can't load CUB dataset HOT 2
- Is there anyway that I get the predicted transformation of an image? HOT 7
- failed to creat process
- How can I use dense_correspondences in downstream tasks?
- Permutations of key point indices of CUB and Spair-71k
- ImportError: Cannot compile splatting CUDA library.
- Running Multi-modal spatial transformer models
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 gangealing.