Comments (2)
I find that opencv is 2 times faster.
package transforms
import (
"fmt"
"image"
"image/jpeg"
"os"
"testing"
"time"
"unsafe"
torch "github.com/wangkuiyi/gotorch"
"gocv.io/x/gocv"
)
func TestJPG(t *testing.T) {
fileName := "188242.jpg"
size := 224
startTime := time.Now()
for i := 0; i < 100; i++ {
file, _ := os.Open(fileName)
defer file.Close()
img, _ := jpeg.Decode(file)
trans1 := Resize(size, size)
o1 := trans1.Run(img)
trans2 := ToTensor()
_ = trans2.Run(o1).Clone()
}
fmt.Println(time.Since(startTime).Seconds())
startTime = time.Now()
for i := 0; i < 100; i++ {
imgCv := gocv.IMRead(fileName, gocv.IMReadColor)
defer imgCv.Close()
gocv.CvtColor(imgCv, &imgCv, gocv.ColorBGRToRGB)
gocv.Resize(imgCv, &imgCv, image.Point{size, size}, 0, 0, 1)
imgCv.ConvertTo(&imgCv, gocv.MatTypeCV32FC3)
imgCv.MultiplyFloat(1.0 / 255.0)
view, _ := imgCv.DataPtrFloat32()
tensor := torch.FromBlob(unsafe.Pointer(&view[0]),
torch.Float, []int64{int64(size), int64(size), 3})
tensor.Permute([]int64{2, 0, 1})
}
fmt.Println(time.Since(startTime).Seconds())
}
go test github.com/wangkuiyi/gotorch/vision/transforms -v -run JPG -count=1
=== RUN TestJPG
0.399983358
0.166660883
--- PASS: TestJPG (0.58s)
PASS
ok github.com/wangkuiyi/gotorch/vision/transforms 1.318s
go test github.com/wangkuiyi/gotorch/vision/transforms -v -run JPG -count=1
=== RUN TestJPG
0.42601828
0.149734561
--- PASS: TestJPG (0.59s)
PASS
ok github.com/wangkuiyi/gotorch/vision/transforms 0.876s
go test github.com/wangkuiyi/gotorch/vision/transforms -v -run JPG -count=1
=== RUN TestJPG
0.384203016
0.156132424
--- PASS: TestJPG (0.55s)
PASS
ok github.com/wangkuiyi/gotorch/vision/transforms 0.786s
from gotorch.
We decide to use gocv to do transforms in GoTorch. The following are some basic operations provided by gocv:
- Resize: gocv.Resize
- Crop: img.Region
- Flip: gocv.Flip
from gotorch.
Related Issues (20)
- A magic number HOT 1
- runtime.LockOSThread() reduce throughput heavily
- Implement PreFetcher to Increase ImageLoader Throughput HOT 2
- A minimal C++ example to reproduce the problem in #273 HOT 2
- Use the Homebrew version of libtorch on macOS
- torch.GC may hang with a data loader cache
- Wrap BuildIndexVocabulary into a command-line tool
- GoCV decoder skipped some JPEG image in imageloader HOT 2
- ImageLoader shuffle samples at the begging of every each epoch
- Support data parallelism with a GPU cluster HOT 4
- gotorch can load pytorch models? HOT 11
- Unable to install go torch, including windows and ubuntu HOT 2
- Random errors in mnist
- 两年木有更新还能用吗 HOT 2
- Do we support Embedding LSTM GRU Transformer Attention Layers for NLP?
- Cannot build cgotorch on Macbook M1 (arm64) system HOT 1
- Suitable for deployment?
- go get is not working HOT 1
- gotorch.Tensor to gocv.Mat
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 gotorch.