import timedefone_cycle():num =0for i inrange(1,1000000): num +=ireturn numdefdouble_cycle():num =0for i inrange(1000):for j inrange(1000):num +=i*jreturn num deftriple_cycle():num =0for i inrange(100):for j inrange(100):for k inrange(100):num += i*j*kreturn num if __name__=="__main__":start_time = time.time()for i inrange(100):one_cycle()end_time = time.time()print("one_cycle函数运行时间:",(end_time-start_time)/100)start_time = time.time()for i inrange(100):double_cycle()end_time = time.time()print("double_cycle函数运行时间:",(end_time-start_time)/100)start_time = time.time()for i inrange(100):triple_cycle()end_time = time.time()print("triple_cycle函数运行时间:",(end_time-start_time)/100)
import time
import numbaimport warnings
warnings.filterwarnings('ignore')@numba.jitdefone_cycle():num =0for i inrange(1,1000000): num +=ireturn num@numba.jitdefdouble_cycle():num =0for i inrange(1000):for j inrange(1000):num +=i*jreturn num @numba.jitdeftriple_cycle():num =0for i inrange(100):for j inrange(100):for k inrange(100):num += i*j*kreturn num if __name__=="__main__":start_time = time.time()for i inrange(100):one_cycle()end_time = time.time()print("one_cycle函数运行时间:",(end_time-start_time)/100)start_time = time.time()for i inrange(100):double_cycle()end_time = time.time()print("double_cycle函数运行时间:",(end_time-start_time)/100)start_time = time.time()for i inrange(100):triple_cycle()end_time = time.time()print("triple_cycle函数运行时间:",(end_time-start_time)/100)
pytorchhub模块里面有很多模型 https://pytorch.org/hub/ github网址:https://github.com/pytorch/pytorch
import torch
model torch.hub.load(pytorch/vision:v0.10.0, fcn_resnet50, pretrainedTrue)
# or
# model torch.hub.load(pytorch/vision:v0.10.0, fc…