Networks
Нейронные сети и оптические системы
from svetlanna.networks import ...Классы
LinearAutoencoder
Наследует:nn.Module
A simple autoencoder network consisting of consistent encoder and decoder for a simultaneous training. .encode() - forward propagation through encoder elements .decode() - forward propagation through decoder elements
Comment: Works only for a single wavelength, input wavefront [‘h’, ‘w’]
Свойства
deviceМетоды
__init__ constructor
__init__(self, sim_params: SimulationParameters, encoder_elements_list: list[Element] | Iterable[Element], decoder_elements_list: list[Element] | Iterable[Element], to_return: Literal['wf', 'amps'] = 'wf', device: str | torch.device = torch.get_default_device())📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
sim_params | SimulationParameters | Simulation parameters for the task. |
encoder_elements_list | `list[Element] | Iterable[Element]` |
decoder_elements_list | `list[Element] | Iterable[Element]` |
to_return | Literal['wf', 'amps'] | Specifies what to return in .encode() and .decode(). (1) ‘wf’ – just a wavefront as it is (2) ‘amps’ – a wavefront without phases |
device | torch.device | Device. |
encode
encode(self, wavefront_in)Propagation through the encoder part – encode an image wavefront (input).
📤 Возвращает
wavefront_encoded : Wavefront
An encoded input wavefront.
decode
decode(self, wavefront_encoded)Propagation through the decoder part – decode an encoded image.
📤 Возвращает
wavefront_decoded : Wavefront
A decoded wavefront.
forward
forward(self, wavefront_in)📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
None | wavefront_in: Wavefront('bs', 'H', 'W') |
📤 Возвращает
wavefront_encoded, wavefront_decoded : torch.Wavefront
Encoded and decoded wavefronts.
to_specs
to_specs(self) -> Iterable[ParameterSpecs | SubelementSpecs]to
to(self, device: str | torch.device | int) -> 'LinearAutoencoder'ConvLayer4F
Наследует:nn.Module
Diffractive convolutional layer based on a 4f system.
Методы
__init__ constructor
__init__(self, sim_params: SimulationParameters, focal_length: float, conv_diffractive_mask: torch.Tensor, learnable_mask: bool = False, max_phase: float = 2 * torch.pi, fs_method: Literal['fresnel', 'AS'] = 'AS')📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
None | sim_params: SimulationParameters | Simulation parameters for the task. |
None | focal_length: float | A focal length for ThinLense’s in a 4f system. |
None | conv_diffractive_mask: torch.Tensor | An initial mask for a DiffractiveLayer placed between two lenses in the system. |
None | learnable_mask: bool | If True – a mask for a DiffractiveLayer in the 4f system will be learnable. Else – not learnable (const). |
None | max_phase: float | A maximal phase for a Diffractive layer in the system. |
None | fs_method: Literal['fresnel', 'AS'] | A method for FreeSpace’s in the system. |
get_free_space
get_free_space(self)Returns a FreeSpace of a focal length for a 4f system.
get_thin_lens
get_thin_lens(self)Returns a ThinLens with a pre-defined focal length.
get_diffractive_layer
get_diffractive_layer(self)Returns a DiffractiveLayer according to pre-defined settings from init.
It can be trainable or not according to self.learnable_mask flag.
get_conv_layer_4f
get_conv_layer_4f(self)forward
forward(self, input_wf: Wavefront)Forward propagation through a convolutional diffractive system based on a 4f system.
📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
None | input_wf: Wavefront('batch_size', 'H', 'W') | An input wavefront(s). |
📤 Возвращает
: Wavefront
A wavefront after a propagation through a system.
ConvDiffNetwork4F
Наследует:nn.Module
A simple convolutional network with a 4f system as an optical convolutional layer. Comment: -> [4f system (convolution)] -> [some system of elements] ->
Свойства
deviceМетоды
__init__ constructor
__init__(self, sim_params: SimulationParameters, network_elements_list: list, focal_length: float, conv_phase_mask: torch.Tensor, learnable_mask: bool = False, max_phase: float = 2 * torch.pi, fs_method: Literal['fresnel', 'AS'] = 'AS', device: str | torch.device = torch.get_default_device())📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
sim_params | SimulationParameters | Simulation parameters for the task. |
network_elements_list | list | List of Elements for a Network after a convolutional layer (4f system). |
None | focal_length: float | A focal length for ThinLense’s in a 4f system. |
None | conv_phase_mask: torch.Tensor | An initial mask for a DiffractiveLayer placed between two lenses in the system. |
None | learnable_mask: bool | If True – a mask for a DiffractiveLayer will be learnable. Else – not learnable (const). |
None | max_phase: float | A maximal phase for a Diffractive layer in the 4f system. |
None | fs_method: Literal['fresnel', 'AS'] | A method for FreeSpace’s in the system. |
None | `device: str | torch.device` |
forward
forward(self, wavefront_in)📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
None | wavefront_in: Wavefront('bs', 'H', 'W') | Input wavefront or a batch of Wavefronts. |
📤 Возвращает
: torch.Tensor | Wavefront
Output after a Wavefront propagation through a Convolutional layer and the Other Part of all Network.
to_specs
to_specs(self) -> Iterable[ParameterSpecs | SubelementSpecs]to
to(self, device: str | torch.device | int) -> 'ConvDiffNetwork4F'DiffractiveRNN
Наследует:nn.Module
A simple recurrent diffractive network of an architecture proposed in the article: https://www.nature.com/articles/s41566-021-00796-w
Свойства
deviceМетоды
__init__ constructor
__init__(self, sim_params: SimulationParameters, sequence_len: int, fusing_coeff: float, read_in_layer: nn.Sequential, memory_layer: nn.Sequential, hidden_forward_layer: nn.Sequential, read_out_layer: nn.Sequential, detector_layer: nn.Sequential, device: str | torch.device = torch.get_default_device())sim_params: SimulationParameters
Simulation parameters for the task.
sequence_len: int
A size (number of frames) of sequences (of Wavefronts) for prediction.
fusing_coeff: float
A coefficient in a function for a hidden state (lambda in methods of the article).
read_in_layer, memory_layer: nn.Sequential
Systems of elements for a D-RNN parts (see the article).
hidden_forward_layer: nn.Sequential
System for a hidden state after each frame input.
Comment:
mix_i = (1 - fusing_coeff) * read_in_layer(input_i) + fusing_coeff * hidden_i
hidden_i = hidden_forward_layer(mix_i)
read_out_layer, detector_layer: nn.Sequential
System of elements for a D-RNN output. detector_layer ends with a Detector!
device: torch.device
Specified device.
forward
forward(self, subsequence_wf: Wavefront)📥 Параметры
| Параметр | Тип | Описание |
|---|---|---|
None | subsequence_wf: Wavefront('batch_size', 'sequence_len', 'H', 'W') | Wavefronts for a sequence. Comment: works for a single wavelength in SimulationParameters! |
to_specs
to_specs(self) -> Iterable[ParameterSpecs | SubelementSpecs]to
to(self, device: str | torch.device | int) -> 'DiffractiveRNN'