pytorch register_buffer的作用

官方:

Adds a persistent buffer to the module.

This is typically used to register a buffer that should not to be considered a model parameter. For example, BatchNorm’s running_mean is not a parameter, but is part of the persistent state.

Buffers can be accessed as attributes using given names.

向模块添加持久缓冲区。
这通常用于注册不应被视为模型参数的缓冲区。例如,BatchNorm的running_mean不是一个参数,而是持久状态的一部分。
缓冲区可以使用给定的名称作为属性访问。

说明:
应该就是在内存中定义一个常量,同时,模型保存和加载的时候可以写入和读出。

你可能感兴趣的:(pytorch,pytorch)