Comments (5)
To change a numpy HxWxC array to CxHxW, and get the same behavior as if you called ToPILImage() and then ToTensor(), do
npimg = np.transpose(npimg,(2,0,1))
Doing a npimg.reshape()
will not produce the same results
from vision.
I ran into this issue today too, I think a normalize
parameter would be nice as sometimes the image loading function used before this would already put the data into [0,1]
.
@ClementPinard As a quick work-around you can call ToPILImage
first in a Compose
i.e.
transform = Compose([ToPILImage(), ToTensor()])
from vision.
@alykhantejani +1 on the normalize parameter.. even better would be for toTensor not to normalize at all.. isn't that what the Normalize transform is for? I got burned doing a Normalize transform with a ToTensor transform
from vision.
as @alykhantejani said ,another way to get the same effect is using numpy to convert,
assume your image is opencv format,
img_tensor = cv_img[:,:,::-1].transpose((2,0,1)).copy()
# chw, RGB order,[0,255]
img_tensor = torch.from_numpy(img_tensor).float().div(255)
# chw , FloatTensor type,[0,1]
img_tensor = img_tensor.unsqueeze(0)
# nch*w
from vision.
fixed in master
from vision.
Related Issues (20)
- Mypy job is broken
- Regarding IMAGENET1K_V1 and IMAGENET1K_V2 weights
- Compiling resize_image: function interpolate not_implemented HOT 1
- AttributeError: module 'torchvision.transforms' has no attribute 'v2' HOT 1
- Run all torchvision models in one script. HOT 1
- Build fails: error: unknown type name 'j_decompress_ptr' HOT 3
- Differences in CPU vs CUDA resize for uint8 images HOT 2
- Enable Video models for other tasks
- Can't use gaussian_blur if sigma is a tensor on gpu HOT 2
- Mask r-cnn training runs infinitely without output or error HOT 1
- detection AnchorGenerator Source code issues HOT 1
- Video Reader's get_metadata function fails on videos with sound
- Difficulty building on macOS HOT 3
- -
- Typo at `permutate_channels`
- retinanet num_classes includes the background HOT 3
- MacOS unit test jobs are red HOT 2
- Add vision-language models HOT 1
- Add mobilenetv4 support and pretrained models? HOT 3
- Allow passing a file-like object to torchvision.io.video.read_video HOT 4
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 vision.