@Namespace(value="torch::nn") @NoOffset @Properties(inherit=torch.class) public class ModuleListImpl extends ModuleListImplCloneable
Modules that registers its elements.
\rst
.. code-block:: cpp
torch::nn::ModuleList mlist(
torch::nn::Linear(3, 4),
torch::nn::BatchNorm1d(4),
torch::nn::Dropout(0.5)
);
for (const auto &module : *mlist) {
module->pretty_print(std::cout);
}
\endrst
Why should you use ModuleList instead of a simple std::vector? The value
a ModuleList 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 ModuleList applies to each of the
modules it stores (which are each a registered submodule of the
ModuleList). For example, calling
.to(torch::kCUDA) on a ModuleList will move each module in the list to
CUDA memory. For example:
\rst
.. code-block:: cpp
torch::nn::ModuleList mlist(
torch::nn::Linear(3, 4),
torch::nn::BatchNorm1d(4),
torch::nn::Dropout(0.5)
);
// Convert all modules to CUDA.
mlist->to(torch::kCUDA);
\endrst
Finally, ModuleList provides a lightweight container API, such as allowing
iteration over submodules, positional access, adding a new module after
construction via push_back, as well as joining two ModuleLists via
extend.Pointer.CustomDeallocator, Pointer.Deallocator, Pointer.NativeDeallocator, Pointer.ReferenceCounter| Constructor and Description |
|---|
ModuleListImpl() |
ModuleListImpl(Module pointer)
Downcast constructor.
|
ModuleListImpl(Pointer p)
Pointer cast constructor.
|
| Modifier and Type | Method and Description |
|---|---|
SharedModuleVector.Iterator |
begin()
Returns an iterator to the start of the
ModuleList. |
Module |
clone() |
Module |
clone(DeviceOptional device)
Special cloning function for
ModuleList because it does not use
reset(). |
SharedModuleVector.Iterator |
end()
Returns an iterator to the end of the
ModuleList. |
Module |
get(long index)
Like
ptr(index). |
void |
insert(long index,
Module module) |
boolean |
is_empty()
True if there are no modules in the
ModuleList. |
void |
pretty_print(Pointer stream)
Pretty prints the
ModuleList module into the given stream. |
Module |
ptr(long index)
Attempts to return a
std::shared_ptr whose dynamic type is that of the
underlying module at the given index. |
void |
push_back(Module module) |
void |
reset()
reset() is empty for ModuleList, since it does not have parameters of
its own. |
long |
size()
The current size of the
ModuleList container. |
asModule, asModuleapply, apply, apply, apply, apply, apply, apply, apply, buffers, buffers, children, eval, is_serializable, is_training, load, modules, modules, name, named_buffers, named_buffers, named_children, named_modules, named_modules, named_modules, named_parameters, named_parameters, parameters, parameters, register_buffer, register_buffer, register_module, register_module, register_parameter, register_parameter, register_parameter, register_parameter, save, shiftLeft, to, to, to, train, unregister_module, unregister_module, zero_gradaddress, asBuffer, asByteBuffer, availablePhysicalBytes, calloc, capacity, capacity, close, deallocate, deallocate, deallocateReferences, deallocator, deallocator, equals, fill, formatBytes, free, getDirectBufferAddress, getPointer, getPointer, getPointer, getPointer, hashCode, interruptDeallocatorThread, isNull, isNull, limit, limit, malloc, maxBytes, maxPhysicalBytes, memchr, memcmp, memcpy, memmove, memset, offsetAddress, offsetof, offsetof, parseBytes, physicalBytes, physicalBytesInaccurate, position, position, put, realloc, referenceCount, releaseReference, retainReference, setNull, sizeof, sizeof, toString, totalBytes, totalCount, totalPhysicalBytes, withDeallocator, zeropublic ModuleListImpl(Pointer p)
Pointer(Pointer).public ModuleListImpl(Module pointer)
public ModuleListImpl()
@SharedPtr(value="torch::nn::Module") @ByVal public Module clone(@Const @ByRef(nullValue="c10::optional<torch::Device>(c10::nullopt)") DeviceOptional device)
ModuleList because it does not use
reset().clone in class ModuleListImplCloneable@SharedPtr(value="torch::nn::Module") @ByVal public Module clone()
clone in class ModuleListImplCloneablepublic void reset()
reset() is empty for ModuleList, since it does not have parameters of
its own.reset in class ModuleListImplCloneablepublic void pretty_print(@Cast(value="std::ostream*") @ByRef Pointer stream)
ModuleList module into the given stream.pretty_print in class Modulepublic void push_back(Module module)
@ByVal @Cast(value="torch::nn::ModuleListImpl::Iterator*") public SharedModuleVector.Iterator begin()
ModuleList.@ByVal @Cast(value="torch::nn::ModuleListImpl::Iterator*") public SharedModuleVector.Iterator end()
ModuleList.@SharedPtr(value="torch::nn::Module") @ByVal public Module ptr(@Cast(value="size_t") long index)
std::shared_ptr whose dynamic type is that of the
underlying module at the given index. Throws an exception if the index is
out of bounds.@SharedPtr(value="torch::nn::Module") @ByVal @Name(value="operator []") public Module get(@Cast(value="size_t") long index)
ptr(index).@Cast(value="size_t") @NoException(value=true) public long size()
ModuleList container.@Cast(value="bool") @NoException(value=true) public boolean is_empty()
ModuleList.public void insert(long index,
Module module)
Copyright © 2024. All rights reserved.