前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >干货|PyTorch实用代码段集锦

干货|PyTorch实用代码段集锦

作者头像
fishexpert
发布2018-11-21 14:48:19
1.7K0
发布2018-11-21 14:48:19
举报

Facebook公司开源的深度学习框架PyTorch越来越火,PyTorch易于上手。本文节选github中PyTorch的常用实用代码片段,供大家学习参考。

Github链接地址

https://github.com/ptrblck/pytorch_misc

代码总览

  • accumulate_gradients - Comparison of accumulated gradients/losses to vanilla batch update. 链接:https://github.com/ptrblck/pytorch_misc/blob/master/accumulate_gradients.py
  • adaptive_batchnorm- Adaptive BN implementation using two additional parameters: out = a * x + b * bn(x). 链接: https://github.com/ptrblck/pytorch_misc/blob/master/adaptive_batchnorm.py
  • adaptive_pooling_torchvision - Example of using adaptive pooling layers in pretrained models to use different spatial input shapes. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/adaptive_pooling_torchvision.py
  • batch_norm_manual - Comparison of PyTorch BatchNorm layers and a manual calculation. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/batch_norm_manual.py
  • change_crop_in_dataset - Change the image crop size on the fly using a Dataset. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/change_crop_in_dataset.py
  • conv_rnn - Combines a 3DCNN with an RNN; uses windowed frames as inputs. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/conv_rnn.py
  • csv_chunk_read - Provide data chunks from continuous .csv file. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/csv_chunk_read.py
  • densenet_forwardhook - Use forward hooks to get intermediate activations from densenet121. Uses separate modules to process these activations further. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/densenet_forwardhook.py
  • edge_weighting_segmentation - Apply weighting to edges for a segmentation task. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/edge_weighting_segmentation.py
  • image_rotation_with_matrix - Rotate an image given an angle using 1.) a nested loop and 2.) a rotation matrix and mesh grid. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/image_rotation_with_matrix.py
  • LocallyConnected2d - Implementation of a locally connected 2d layer. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/LocallyConnected2d.py
  • mnist_autoencoder - Simple autoencoder for MNIST data. Includes visualizations of output images, intermediate activations and conv kernels. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/mnist_autoencoder.py
  • mnist_permuted - MNIST training using permuted pixel locations. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/mnist_permuted.py
  • model_sharding_data_parallel - Model sharding with DataParallel using 2 pairs of 2 GPUs. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/model_sharding_data_parallel.py
  • momentum_update_nograd - Script to see how parameters are updated when an optimizer is used with momentum/running estimates, even if gradients are zero. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/momentum_update_nograd.py
  • shared_array - Script to demonstrate the usage of shared arrays using multiple workers. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/shared_array.py
  • unet_demo - Simple UNet demo. 链接: https://github.com/ptrblck/pytorch_misc/blob/master/unet_demo.py
  • weighted_sampling - Usage of WeightedRandomSampler using an imbalanced dataset with class imbalance 99 to 1 链接: https://github.com/ptrblck/pytorch_misc/blob/master/weighted_sampling.py
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2018-11-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 深度学习与数据挖掘实战 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档