Module tripleblind.network

The network object represents a neural network.

Networks structures can be build using the NetworkBuilder. These networks must be trained, then the resulting model Asset can be used to perform inference.

Typical usage is something like this:

builder = tb.NetworkBuilder().
builder.add_conv2d_layer(1, 32, 3, 1)
builder.add_relu()
# ... continue adding layers
training_model = tb.create_network("new network", builder)

# train the network (would require more training parameters)
result = training_model.train(dataset=[dataset_train0, dataset_train1], ...)

# use the trained model
trained_model = tb.Model.cast(result.asset)
output = trained_model.infer(dataset="airplane.jpg)
if output:
    print(output.table.dataframe.values.flatten())

See NetworkBuilder for more information.

Functions

def create_network(name: str, builder: NetworkBuilder, description: Optional[str] = None, is_discoverable: bool = True, asset_cost: int = 0, persist: bool = False, session: Optional[Session] = None, is_federated_learning_model: bool = False) -> 'ModelTrainerAsset'

Create an empty network in the Router index (usually for later training)

Args

name : str
Name of the new network to create
builder : NetworkBuilder
[description]
description : Optional[str], optional
Longer description of the network.
is_discoverable : bool, optional
Should network be discoverable by others?
asset_cost : int, optional
Price of accessing this network (in US cents)
persist : bool
By default a uniquely named temporary network asset is created, but the asset can be persisted by setting this parameter to True.
session : Session, optional
A connection session. If not specified, the default session is used.
is_federated_learning_model : bool
model and protocol are intended to be used with federated learning.

Raises

Exception
Raised if unable to create the network.

Returns

ModelTrainerAsset
New empty network (algorithm) asset
def create_vertical_network(name: str, server: NetworkBuilder, clients: List[NetworkBuilder], description: Optional[str] = None, is_discoverable: bool = True, asset_cost: int = 0, session: Optional[Session] = None, is_psi: bool = False, persist: bool = False, strategy: Optional[str] = None) -> 'ModelTrainerAsset'

Create an empty vertically partitioned network in the Router index (usually for later training)

Args

name : str
Name of the new network to create
server : NetworkBuilder
Network definition for the server unifying clients
clients : List[NetworkBuilder]
Network definitions for the individual clients
description : Optional[str], optional
Longer description of the network.
is_discoverable : bool, optional
Should network be discoverable by others?
asset_cost : int, optional
Price of accessing this network (in US cents)
session : Session, optional
A connection session. If not specified, the default session is used.
is_psi : bool
True if will be used with PSI. Defaults to False.
persist : bool
By default a uniquely named temporary network asset is created, but the asset can be persisted by setting this parameter to True.
strategy : Optional[str], optional
description. Defaults to None.

Returns

Asset
New empty network (algorithm) asset
def create_word_embedding(name: str, embedding_path: Union[Path, str], vocab_path: Union[Path, str] = None, description: Optional[str] = None, is_discoverable: bool = False, asset_cost: int = 0, session: Optional[Session] = None, strategy: Optional[str] = None) -> Asset

Create an empty network on the user's Access Point (usually for later training)

Args

name : str
Name of the new network to create
file_handle : str or Path
Path to model
vocab_path : str or Path
Path to a file with the vocabulary.
description : Optional[str], optional
Longer description of the network.
is_discoverable : bool, optional
Should network be discoverable by others?
asset_cost : int, optional
Price of accessing this network (in US cents)
session : Session, optional
A connection session. If not specified, the default session is used.
strategy : str, optional
Upload strategy Use 'stream' to use a web socket, or 'post' to perform a simple post to position the asset. Default is 'stream'.

Raises

Exception
Raised if unable to create the network.

Returns

Asset
Model asset
def load_model(filepath)
def upload_trained_network(name: str, file_handle: Union[Path, str], description: Optional[str] = None, is_discoverable: bool = True, asset_cost: int = 0, session: Optional[Session] = None, allow_overwrite: bool = False, strategy: Optional[str] = None) -> Asset

Create an empty network on the user's Access Point (usually for later training)

Args

name : str
Name of the new network to create
file_handle : str or Path
Path to model
description : Optional[str], optional
Longer description of the network.
is_discoverable : bool, optional
Should network be discoverable by others?
asset_cost : int, optional
Price of accessing this network (in US cents)
session : Session, optional
A connection session. If not specified, the default session is used.
allow_overwrite : bool, optional
If False an exception will be thrown if the asset name already exists. If True, an existing asset will be overwritten.
strategy : str, optional
Upload strategy Use 'stream' to use a web socket, or 'post' to perform a simple post to position the asset. Default is 'stream'.

Raises

Exception
Raised if unable to create the network.

Returns

Asset
Model asset

Classes

class ModelEnsemble (server_model, *clients_models)

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing to nest them in a tree structure. You can assign the submodules as regular attributes::

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will have their parameters converted too when you call :meth:to, etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

:ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool

Initializes internal Module state, shared by both nn.Module and ScriptModule.

Ancestors

  • torch.nn.modules.module.Module

Class variables

var dump_patches : bool
var training : bool

Methods

def forward(self, *input_x) -> Callable[..., Any]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the :class:Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.