GithubHelp home page GithubHelp logo

convert_tensor's Introduction

  1. convert_tensor.py
    将三维数组image(h,w,c)转换为四维数组Tensor(b,h,w,a), 其中 c=ba, 当c<ba时将数组补零. 效果示例如下: image

不能直接用reshape是因为我们要保留图像数据的完整性, 这时直接进行切片操作即可:image_hwc[:,:,i]
输入h=2,w=2,c=5,a=2
输出:
image =
[[[ 0 1 2 3 4] [ 5 6 7 8 9]]

[[10 11 12 13 14] [15 16 17 18 19]]]
Tensor = [[[[ 0 1] [ 5 6]]

[[10 11] [15 16]]]

[[[ 2 3] [ 7 8]]

[[12 13] [17 18]]]

[[[ 4 0] [ 9 0]]

[[14 0] [19 0]]]]

转换成功.
2. torch_tensor.py
在pytorch中, 我们可以用torch自带的to_tensor()将image(h,w,c)转换为image(c,w,h),之后再由DataLoader(train_data, batch_size=n,shuffle=True)实现Tensor的转换.
输入: batch_size=16, BosphorusDB数据库的115张人脸图像
输出:
torch.Size([16, 3, 224, 224]) torch.Size([16])

convert_tensor's People

Contributors

nalilik avatar

Watchers

James Cloos avatar

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.