python 批量resize效能比較
torch是最快的,能快1ms
分別是5ms 9ms 6ms,但是torch 佔用cpu很高。
import time
import cv2
import torch
img = cv2.imread('d:/guo.jpg') # modify the image path to yours
img =cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
pic_w=1200
start=time.time()
tensor_in = torch.FloatTensor(img)
for i in range(10):
pic_w = int(pic_w * 0.8)
tensor_in = tensor_in.resize_(pic_w,pic_w,3)
print('time0',time.time()-start)
pic_w=1200
start=time.time()
for i in range(10):
pic_w=int(pic_w*0.8)
a=cv2.resize(img,(pic_w,pic_w))
print('time1',time.time()-start)
pic_w = 1200
start = time.time()
for i in range(10):
pic_w = int(pic_w * 0.8)
img= cv2.resize(img, (pic_w, pic_w))
print('time2', time.time() - start)
torch.Tensor特別佔用時間,下面程式碼需要58ms
pic_w=1200
start=time.time()
for i in range(10):
tensor_in = torch.FloatTensor(img)
pic_w = int(pic_w * 0.8)
tensor_in = tensor_in.resize_(pic_w,pic_w,3)
接著往下看:
這個最牛:幾乎不需要時間:
pic_w=1200
start=time.time()
for i in range(10):
tensor_in = torch.from_numpy(img)
pic_w = int(pic_w * 0.8)
tensor_in = tensor_in.resize_(pic_w,pic_w,3)
相關文章
- 批量更新效能比較
- JAVA IO效能比較Java
- Python、JavaScript和Rust的Web效能比較 - AlexPythonJavaScriptRustWeb
- 【MyBatis】幾種批量插入效率的比較MyBatis
- 批量更新資料方法比較測試
- Python解惑:整數比較 is ==的比較Python
- 在MongoDB下使用JS和Python的效能比較MongoDBJSPython
- Java中List集合效能比較Java
- 排序演算法效能比較排序演算法
- JavaScript 字串連線效能比較JavaScript字串
- 效能比較工具runStats_pkg
- 批量插入 1 萬條資料,DB 查詢構造器和原生 SQL 效能比較SQL
- python字串比較大小Python字串
- Python 模板引擎比較Python
- Python 與 Javascript 比較PythonJavaScript
- 比較 python & perl(轉)Python
- Go和Python比較的話,哪個比較好?GoPython
- 堆排序和快速排序效能比較排序
- Java Bean Copy元件的效能比較JavaBean元件
- Java JIT與AOT效能比較 - foojayJava
- 七種WebSocket框架的效能比較Web框架
- C#比較dynamic和Dictionary效能C#
- sqlldr和oracle_datapump效能比較SQLOracle
- PHP autoload與include效能比較PHP
- eAccelerator的安裝和效能比較
- DECODE和CASE的效能比較
- Python的內建比較函式cmp比較原理剖析Python函式
- Python 解惑:整數比較Python
- Python與Excel VBA比較PythonExcel
- python pil resize 用法Python
- 雲主機的硬碟IO效能比較硬碟
- PostgreSQL、Redis與Memcached的效能比較 - CYBERTECSQLRedis
- WCF與ASP.NET Core效能比較ASP.NET
- insert的不同場景效能比較
- Linux壓縮工具的效能比較Linux
- XML資料讀取方式效能比較XML
- 百萬行資料查詢效能比較
- Apache與Nginx的優缺點、效能比較,到底選擇哪個比較好?ApacheNginx