pytorch api torch.nn.Module

版权声明:本文为作者创作,转载请注明出处:http://blog.csdn.net/claroja,如有商业用途请联系QQ:63183535。 https://blog.csdn.net/claroja/article/details/85329178

神经网络层的基础类,我们构建的神经网络类要继承这个类.
模块可以包含其他模块.

方法 描述
add_module(name, module) 插入一个子模块
apply(fn)
buffers(recurse=True) 返回模块的buffers
children() Returns an iterator over immediate children modules.
cpu() 将所有参数和buffer移动到cpu
cuda(device=None) 将所有参数移动到gpu
double() 将单浮点参数转化为双浮点参数
dump_patches = FALSE
eval() Sets the module in evaluation mode.
extra_repr() Set the extra representation of the module
float() Casts all floating point parameters and buffers to float datatype.
forward(*input) 向前传播方法,子类必须重写
half() 将所有浮点参数和buffer和转换为half
load_state_dict(state_dict, strict=True) Copies parameters and buffers from state_dict into this module and its descendants.
modules() returns an iterator over all modules in the network.
named_buffers(prefix=’’, recurse=True) Returns an iterator over module buffers, yielding both the name of the buffer as well as the buffer itself.
named_children() Returns an iterator over immediate children modules
named_modules(memo=None, prefix=’’) Returns an iterator over all modules in the network
named_parameters(prefix=’’, recurse=True) Returns an iterator over module parameters
parameters(recurse=True) Returns an iterator over module parameters.
register_backward_hook(hook) Registers a backward hook on the module.
register_buffer(name, tensor) Adds a persistent buffer to the module.
register_forward_hook(hook) Registers a forward hook on the module.
register_forward_pre_hook(hook) Registers a forward pre-hook on the module.
register_parameter(name, param) Adds a parameter to the module.
state_dict(destination=None, prefix=’’, keep_vars=False) Returns a dictionary containing a whole state of the module.
to(*args, **kwargs) Moves and/or casts the parameters and buffers.
train(mode=True) Sets the module in training mode.
type(dst_type) Casts all parameters and buffers to dst_type.
zero_grad() 将所有模型的梯度参数设置为0

参考文献:
https://pytorch.org/docs/stable/nn.html#torch.nn.Module

猜你喜欢

转载自blog.csdn.net/claroja/article/details/85329178
今日推荐