Spaces:
Build error
Build error
File size: 6,184 Bytes
8a01471 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
/**
* NN3D Schema TypeScript Types
* Auto-generated from nn3d.schema.json
*/
// Schema version
export const NN3D_SCHEMA_VERSION = '1.0.0';
// Layer type enumeration
export type LayerType =
| 'input'
| 'output'
| 'conv1d'
| 'conv2d'
| 'conv3d'
| 'convTranspose2d'
| 'depthwiseConv2d'
| 'separableConv2d'
| 'linear'
| 'dense'
| 'embedding'
| 'batchNorm1d'
| 'batchNorm2d'
| 'layerNorm'
| 'groupNorm'
| 'instanceNorm'
| 'dropout'
| 'relu'
| 'leakyRelu'
| 'gelu'
| 'silu'
| 'sigmoid'
| 'tanh'
| 'softmax'
| 'maxPool1d'
| 'maxPool2d'
| 'avgPool2d'
| 'globalAvgPool'
| 'adaptiveAvgPool'
| 'flatten'
| 'reshape'
| 'concat'
| 'add'
| 'multiply'
| 'split'
| 'attention'
| 'multiHeadAttention'
| 'selfAttention'
| 'crossAttention'
| 'lstm'
| 'gru'
| 'rnn'
| 'transformer'
| 'encoderBlock'
| 'decoderBlock'
| 'residualBlock'
| 'upsample'
| 'interpolate'
| 'pad'
| 'custom';
// Tensor shape (dimensions can be numbers or dynamic strings)
export type TensorShape = (number | string)[];
// 3D position
export interface Position3D {
x: number;
y: number;
z: number;
}
// Weight reference for loading weights
export interface WeightRef {
url?: string;
offset?: number;
size?: number;
dtype?: 'float16' | 'float32' | 'float64' | 'int32' | 'int64' | 'bool';
shape?: TensorShape;
}
// Layer parameters
export interface LayerParams {
inChannels?: number;
outChannels?: number;
inFeatures?: number;
outFeatures?: number;
kernelSize?: number | number[];
stride?: number | number[];
padding?: number | string | number[];
dilation?: number | number[];
groups?: number;
bias?: boolean;
numHeads?: number;
hiddenSize?: number;
dropoutRate?: number;
eps?: number;
momentum?: number;
affine?: boolean;
numEmbeddings?: number;
embeddingDim?: number;
axis?: number;
scaleFactor?: number;
mode?: string;
[key: string]: unknown;
}
// Graph node (layer)
export interface NN3DNode {
id: string;
type: LayerType;
name: string;
params?: LayerParams;
inputShape?: TensorShape;
outputShape?: TensorShape;
position?: Position3D;
weights?: WeightRef;
attributes?: Record<string, unknown>;
group?: string;
depth?: number;
}
// Graph edge (connection)
export interface NN3DEdge {
id?: string;
source: string;
target: string;
sourcePort?: number;
targetPort?: number;
tensorShape?: TensorShape;
dtype?: 'float16' | 'float32' | 'float64' | 'int32' | 'int64' | 'bool';
label?: string;
}
// Subgraph for grouping layers
export interface NN3DSubgraph {
id: string;
name: string;
type?: 'sequential' | 'residual' | 'parallel' | 'attention' | 'custom';
nodes: string[];
color?: string;
collapsed?: boolean;
}
// Graph structure
export interface NN3DGraph {
nodes: NN3DNode[];
edges: NN3DEdge[];
subgraphs?: NN3DSubgraph[];
}
// Model metadata
export interface NN3DMetadata {
name: string;
description?: string;
framework?: 'pytorch' | 'tensorflow' | 'keras' | 'onnx' | 'jax' | 'custom';
author?: string;
created?: string;
tags?: string[];
inputShape?: TensorShape;
outputShape?: TensorShape;
totalParams?: number;
trainableParams?: number;
}
// Visualization configuration
export interface VisualizationConfig {
layout?: 'layered' | 'force' | 'circular' | 'hierarchical' | 'custom';
theme?: 'light' | 'dark' | 'blueprint';
layerSpacing?: number;
nodeScale?: number;
colorScheme?: Record<string, string>;
camera?: {
position?: Position3D;
target?: Position3D;
fov?: number;
};
showLabels?: boolean;
showEdges?: boolean;
edgeStyle?: 'line' | 'tube' | 'arrow' | 'bezier';
}
// Activation data for visualization
export interface ActivationData {
source?: 'file' | 'live' | 'embedded';
url?: string;
nodeActivations?: Record<string, {
min?: number;
max?: number;
mean?: number;
std?: number;
histogram?: number[];
}>;
}
// Complete NN3D model
export interface NN3DModel {
version: string;
metadata: NN3DMetadata;
graph: NN3DGraph;
visualization?: VisualizationConfig;
activations?: ActivationData;
}
// Layer category for visualization grouping
export type LayerCategory =
| 'input'
| 'output'
| 'convolution'
| 'linear'
| 'normalization'
| 'activation'
| 'pooling'
| 'attention'
| 'recurrent'
| 'transform'
| 'merge'
| 'other';
// Map layer types to categories
export const LAYER_CATEGORIES: Record<LayerType, LayerCategory> = {
input: 'input',
output: 'output',
conv1d: 'convolution',
conv2d: 'convolution',
conv3d: 'convolution',
convTranspose2d: 'convolution',
depthwiseConv2d: 'convolution',
separableConv2d: 'convolution',
linear: 'linear',
dense: 'linear',
embedding: 'linear',
batchNorm1d: 'normalization',
batchNorm2d: 'normalization',
layerNorm: 'normalization',
groupNorm: 'normalization',
instanceNorm: 'normalization',
dropout: 'normalization',
relu: 'activation',
leakyRelu: 'activation',
gelu: 'activation',
silu: 'activation',
sigmoid: 'activation',
tanh: 'activation',
softmax: 'activation',
maxPool1d: 'pooling',
maxPool2d: 'pooling',
avgPool2d: 'pooling',
globalAvgPool: 'pooling',
adaptiveAvgPool: 'pooling',
flatten: 'transform',
reshape: 'transform',
concat: 'merge',
add: 'merge',
multiply: 'merge',
split: 'merge',
attention: 'attention',
multiHeadAttention: 'attention',
selfAttention: 'attention',
crossAttention: 'attention',
lstm: 'recurrent',
gru: 'recurrent',
rnn: 'recurrent',
transformer: 'attention',
encoderBlock: 'attention',
decoderBlock: 'attention',
residualBlock: 'merge',
upsample: 'transform',
interpolate: 'transform',
pad: 'transform',
custom: 'other',
};
// Default colors for layer categories
export const DEFAULT_CATEGORY_COLORS: Record<LayerCategory, string> = {
input: '#4CAF50',
output: '#F44336',
convolution: '#2196F3',
linear: '#9C27B0',
normalization: '#FF9800',
activation: '#FFEB3B',
pooling: '#00BCD4',
attention: '#E91E63',
recurrent: '#673AB7',
transform: '#795548',
merge: '#607D8B',
other: '#9E9E9E',
};
|