博文

目前显示的是 四月, 2019的博文

gpu_flow 安装过程出错解决方法

gpu_flow 安装过程出错解决方法 cannot find -lopencv_dep_cudart cmake -D CUDA_USE_STATIC_CUDA_RUNTIME=OFF 在CmakeLists.txt中添加并不行,源文件中有这个了。 set(CUDA_USE_STATIC_CUDA_RUNTIME OFF) 解决完这个问题又会出现下面的问题 /usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference toTIFFIsTiled@LIBTIFF_4.0’ 这是Anaconda的问题,只要把anaconda下面的libtiff.so移开就可以了 mv /home/user_name/anaconda2/lib/libtiff.so* ~/user_name/bak/ 参考 https://github.com/opencv/opencv/issues/6542 https://www.itread01.com/content/1515423369.html

torch.no_grad()与梯度叠加

torch.no_grad()与梯度叠加 torch.no_grad with torch.no_grad(): output = model(img) 在计算网络输出的时候,不存储梯度,能节约很多显存。但是多出来的空间用于增加batch size, 速度并没有提升。 梯度叠加 在显存不足的时候,若是想要实现增大batch size, 可累积梯度,在多个batch之后一起更新网络参数。 # some code # Initialize dataset with batch size 10 opt.zero_grad() for i, (input, target) in enumerate(dataset): pred = net(input) loss = crit(pred, target) # one graph is created here loss.backward() # graph is cleared here if (i+1)%10 == 0: # every 10 iterations of batches of size 10 opt.step() opt.zero_grad() 参考 [1] https://www.zhihu.com/question/303070254 [2] https://discuss.pytorch.org/t/why-do-we-need-to-set-the-gradients-manually-to-zero-in-pytorch/4903/20