This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.nn as nn | |
| import numpy as np | |
| # Определяем инвариантные функции | |
| class UniVariateFunction(nn.Module): | |
| def __init__(self, output_size): | |
| super(UniVariateFunction, self).__init__() | |
| self.linear = nn.Linear(1, output_size) | |
| def forward(self, x): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| from torchvision import datasets, transforms | |
| from torch.utils.data import DataLoader | |
| import numpy as np | |
| class CapsuleLayer(nn.Module): | |
| def __init__(self, num_capsules, num_route_nodes, in_channels, out_channels, kernel_size=None, stride=None): | |
| super(CapsuleLayer, self).__init__() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import torch | |
| import torch.nn as nn | |
| from torchvision import datasets | |
| from torchvision import transforms | |
| from torch.utils.data.sampler import SubsetRandomSampler | |
| import gc | |
| # Конфигурация устройства (GPU/CPU) | |
| device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorflow.keras import layers | |
| # Генератор | |
| def build_generator(): | |
| model = tf.keras.Sequential() | |
| model.add(layers.Dense(128, input_dim=100, activation='relu')) | |
| model.add(layers.Dense(784, activation='sigmoid')) | |
| return model |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as F | |
| class TransformerEncoderLayer(nn.Module): | |
| """ | |
| Один слой энкодера трансформера (Post-LN). | |
| Аргументы: | |
| d_model (int): Размерность эмбеддингов (например, 512) |