/usr/local/lib64/python3.6/site-packages/torch/nn/modules/__pycache__
Edit: /usr/local/lib64/python3.6/site-packages/torch/nn/modules/__pycache__/container.cpython-36.pyc (27970B)
3
Egf @ s d dl Z d dlmZmZ d dlmZ d dlZd dlZddl m
Z
d dlmZ d dl
mZmZmZmZmZmZmZmZmZmZmZ erd dlmZ ed e
d
ZG dd de
ZG d
d de
ZG dd de
ZG dd de
ZG dd de
Z G dd de
Z!dS ) N)OrderedDictabc)islice )Module)_copy_to_script_wrapper)AnyDictIterableIteratorMappingOptional
TYPE_CHECKINGoverloadTupleTypeVarUnion) ParameterT)boundc s$ e Zd Zedd fddZ ZS ) ContainerN)kwargsreturnc s> t t| j tjd x |j D ]\}}| j|| q"W d S )Nzmnn.Container is deprecated. All of it's functionality is now implemented in nn.Module. Subclass that instead.)superr __init__warningswarnitems
add_module)selfr keyvalue) __class__ F/usr/local/lib64/python3.6/site-packages/torch/nn/modules/container.pyr s
zContainer.__init__)__name__
__module____qualname__r r
__classcell__r# r# )r" r$ r s r c s e Zd ZU dZeeef eeddddZ edddddZ fd dZ e
d
ddZee
d e
f d
d
dZeeddddZe
eef ddddZeed
ddZe fddZeee d
ddZdd Z ZS )
Sequentiala A sequential container.
Modules will be added to it in the order they are passed in the
constructor. Alternatively, an ``OrderedDict`` of modules can be
passed in. The ``forward()`` method of ``Sequential`` accepts any
input and forwards it to the first module it contains. It then
"chains" outputs to inputs sequentially for each subsequent module,
finally returning the output of the last module.
The value a ``Sequential`` provides over manually calling a sequence
of modules is that it allows treating the whole container as a
single module, such that performing a transformation on the
``Sequential`` applies to each of the modules it stores (which are
each a registered submodule of the ``Sequential``).
What's the difference between a ``Sequential`` and a
:class:`torch.nn.ModuleList`? A ``ModuleList`` is exactly what it
sounds like--a list for storing ``Module`` s! On the other hand,
the layers in a ``Sequential`` are connected in a cascading way.
Example::
# Using Sequential to create a small model. When `model` is run,
# input will first be passed to `Conv2d(1,20,5)`. The output of
# `Conv2d(1,20,5)` will be used as the input to the first
# `ReLU`; the output of the first `ReLU` will become the input
# for `Conv2d(20,64,5)`. Finally, the output of
# `Conv2d(20,64,5)` will be used as input to the second `ReLU`
model = nn.Sequential(
nn.Conv2d(1,20,5),
nn.ReLU(),
nn.Conv2d(20,64,5),
nn.ReLU()
)
# Using Sequential with OrderedDict. This is functionally the
# same as the above code
model = nn.Sequential(OrderedDict([
('conv1', nn.Conv2d(1,20,5)),
('relu1', nn.ReLU()),
('conv2', nn.Conv2d(20,64,5)),
('relu2', nn.ReLU())
]))
N)argsr c G s d S )Nr# )r r* r# r# r$ r L s zSequential.__init__zOrderedDict[str, Module])argr c C s d S )Nr# )r r+ r# r# r$ r P s c sz t t| j t|dkrPt|d trPxL|d j D ]\}}| j|| q6W n&x$t|D ]\}}| jt || qZW d S )Nr r )
r r) r len
isinstancer r r enumeratestr)r r* r moduleidx)r" r# r$ r T s )r c C sR t | }tj|}| | ko&|k n s:tdj|||; }tt||dS )z#Get the idx-th item of the iteratorzindex {} is out of rangeN)r, operatorindex
IndexErrorformatnextr )r iteratorr1 sizer# r# r$ _get_item_by_idx] s
zSequential._get_item_by_idxc C s<