Time contrast for writing images

Source: Internet
Author: User
Tags join

When writing an image, there are some common methods to choose from, when saved with torch, found that the tochvision.utils.save_image time is a bit long, made a simple comparison:

Import Cv2 from
torchvision.utils import save_image
import Torch
import NumPy as NP
import
time Import OS from
ImageIO import imwrite
folder = './. Testuse '

img = Np.ones ((3, 2336, 3504), np.uint8)
# cv2
time1 = Time.time ()
save_name = Os.path.join ( folder, ' Cv2.png ')
cv2.imwrite (Save_name, img)
time.time ()-time1
# 0.0007767677307128906

# ImageIO
time1 = Time.time ()
save_name = os.path.join (folder, ' Imageio.png ')
imwrite (Save_name, Img.transpose (1, 2, 0))
time.time ()-time1
# 0.7609069347381592

# torchvision
time1 = Time.time ()
save_name = os.path.join (folder, ' Torchvision.png ')
save_image (torch. Tensor (IMG), save_name)
time.time ()-time1
# 1.1047229766845703

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.