{"id":21530699,"url":"https://github.com/timmoth/vcortex","last_synced_at":"2025-04-10T00:13:36.627Z","repository":{"id":261972105,"uuid":"885868888","full_name":"Timmoth/vcortex","owner":"Timmoth","description":"Lightweight CPU / GPU machine learning for dotnet","archived":false,"fork":false,"pushed_at":"2024-11-16T15:17:50.000Z","size":404,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T00:13:24.711Z","etag":null,"topics":["ai","dotnet","machine-learning","neural-network"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Timmoth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-09T15:55:48.000Z","updated_at":"2025-03-31T17:17:14.000Z","dependencies_parsed_at":"2024-11-09T16:41:38.726Z","dependency_job_id":null,"html_url":"https://github.com/Timmoth/vcortex","commit_stats":null,"previous_names":["timmoth/vcortex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timmoth%2Fvcortex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timmoth%2Fvcortex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timmoth%2Fvcortex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Timmoth%2Fvcortex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Timmoth","download_url":"https://codeload.github.com/Timmoth/vcortex/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131315,"owners_count":21052819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","dotnet","machine-learning","neural-network"],"created_at":"2024-11-24T02:09:47.384Z","updated_at":"2025-04-10T00:13:36.598Z","avatar_url":"https://github.com/Timmoth.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n   \u003cdiv style=\"width:640;height:320\"\u003e\n       \u003cimg style=\"width: inherit\" src=\"./banner.png\"\u003e\n\u003c/div\u003e\n\u003c/p\u003e\nLightweight \u0026 high performance CPU/GPU machine learning library for .NET, designed for neural network training and inference.\n\n[![Core](https://img.shields.io/nuget/v/vcortex?label=core)](https://www.nuget.org/packages/vcortex)\n[![Cpu](https://img.shields.io/nuget/v/vcortex.cpu?label=cpu)](https://www.nuget.org/packages/vcortex.cpu)\n[![Gpu](https://img.shields.io/nuget/v/vcortex.gpu?label=gpu)](https://www.nuget.org/packages/vcortex.gpu)\n\n## Simple image classification architecture\nSetting up a neural network for image classification tasks.\n\n```csharp\n// Define the input structure\nvar inputConfig = new ConvolutionInputConfig\n{\n    Width = 28,         // Image width in pixels\n    Height = 28,        // Image height in pixels\n    Grayscale = true    // True for grayscale images, false for RGB\n};\n\n// Define your networks architecture\nvar network = new NetworkBuilder(inputConfig)\n    .Add(new Convolution\n    {\n        Activation = ActivationType.LeakyRelu,    // Activation function\n        KernelSize = 3,                           // Width/height of convolutional filter\n        KernelsPerChannel = 32,                   // Number of filters per input channel\n        Padding = 1,                              // Padding added to image borders\n        Stride = 1                                // Step size of the filter\n    })\n    .Add(new Maxpool\n    {\n        PoolSize = 2                              // Size of the pooling window\n    })\n    .Add(new Dense\n    {\n        Activation = ActivationType.LeakyRelu,    // Activation function for dense layer\n        Neurons = 128                             // Number of neurons in dense layer\n    })\n    .Add(new Dropout\n    {\n        DropoutRate = 0.2f                        // Dropout rate for regularization\n    })\n    .Add(new Softmax\n    {\n        Neurons = 10                              // Number of output classes\n    })\n    .Build();\n```\n## Simple regression architecture\nSetting up a neural network for regression tasks.\n\n```csharp\n// Define the input structure\nvar inputConfig = new ConnectedInputConfig()\n{\n    NumInputs = 32,         // Number of inputs\n};\n\n// Define your networks architecture\nvar network = new NetworkBuilder(inputConfig)\n    .Add(new Dense\n    {\n        Activation = ActivationType.Sigmoid,    // Activation function for dense layer\n        Neurons = 128                           // Number of neurons in dense layer\n    })\n    .Add(new Dense\n    {\n        Activation = ActivationType.Sigmoid,    // Activation function for dense layer\n        Neurons = 32                            // Number of neurons in dense layer\n    })\n    .Build();\n```\n\n## Training / Testing Quickstart\nTraining and testing a neural network\n\n```csharp\n// Define the training parameters   \nvar trainingConfig = new TrainConfig\n{\n    Epochs = 20,                                  // Total training iterations over dataset\n    Scheduler = new ExponentialDecay()\n    {\n        InitialLearningRate = 0.001f,             // Starting learning rate\n        DecayRate = 0.05f                         // Rate at which learning rate decays\n    },\n    Optimizer = new Adam(),                       // Optimization algorithm\n    LossFunction = LossFunction.Mse,              // Loss function to minimize\n    BatchSize = 100                               // Number of samples per training batch\n};\n\n// Create a CPU trainer\nvar trainer = new CpuNetworkTrainer(network, trainingConfig);\n// Or create a GPU trainer\nvar trainer = new GpuNetworkTrainer(GpuType.Cuda, 0, net, trainingConfig);\n\n// Initialize the trainable parameters to random values\ntrainer.InitRandomParameters();                    // Randomize model parameters\n// Train\nvar trainData = new List\u003c(float[] input, float[] output)\u003e();\ntrainer.Train(trainData);                          // Train model on training data\n// Test\nvar testData = new List\u003c(float[] input, float[] output)\u003e();\ntrainer.Test(testData, 0.1f);                      // Test model on test data\n```\n\n## Persistence\nSave and load network architecture and parameters.\n\n```csharp\n// Load the network architecture from disk\nvar network = NetworkConfig.DeserializeFromDisk(\"./network.json\");\n// Save the network architecture to disk\nnetwork.SerializeToDisk(\"./network.json\");\n\n// Load the network parameters from disk\ntrainer.SaveParametersToDisk(\"./weights.bin\");\n// Save the network parameters to disk\ntrainer.ReadParametersFromDisk(\"./weights.bin\");\n\n// Load the network parameters into an array\nfloat[] parameters = trainer.GetParameters();  // Retrieve network parameters as array\n// Load the network parameters from an array\ntrainer.LoadParameters(parameters);            // Load parameters from an array\n```\n\n## Layers\nCommon neural network layer configurations.\n\n### Convolution\nConfiguration for convolutional layer used for feature extraction in image data.\n\n\n```\n{\n    \"$type\": \"convolution\",           # Specifies layer type as convolutional\n    \"stride\": 1,                      # Filter movement per step\n    \"padding\": 1,                     # Padding pixels around the image border\n    \"kernels_per_channel\": 32,        # Number of filters per input channel\n    \"kernel_size\": 3,                 # Size of each filter (e.g., 3x3)\n    \"activation\": 2                   # Activation function type\n}\n```\n\n### Dense\nConfiguration for a fully connected (dense) layer used to combine features from previous layers.\n\n```\n{\n    \"$type\": \"dense\",                 # Specifies layer type as dense\n    \"activation\": 2,                  # Activation function type\n    \"neurons\": 128                    # Number of neurons in the dense layer\n}\n```\n\n### Dropout\nConfiguration for dropout layer used for regularization to prevent overfitting.\n\n```\n{\n    \"$type\": \"dropout\",               # Specifies layer type as dropout\n    \"dropout_rate\": 0.2               # Fraction of units to drop\n}\n```\n\n### Maxpool\nConfiguration for max pooling layer used to reduce spatial dimensions.\n\n```\n{\n    \"$type\": \"maxpool\",               # Specifies layer type as max pooling\n    \"pool_size\": 2                    # Size of the pooling filter\n}\n```\n\n### Softmax\nConfiguration for softmax layer used in the output for classification tasks.\n\n```\n{\n    \"$type\": \"softmax\",               # Specifies layer type as softmax for output\n    \"neurons\": 10                     # Number of output classes\n}\n```\n\n## Optimizers\nConfigurable algorithms for optimizing model weights.\n\n### AdaDelta\nOptimizer that adapts learning rate based on a moving window of gradient updates.\n\n```\n{\n    \"$type\": \"adadelta\",              # AdaDelta optimizer type\n    \"rho\": 0.1,                       # Decay rate for squared gradient\n    \"epsilon\": 1E-08                  # Small constant for numerical stability\n}\n```\n\n### AdaGrad\nOptimizer that adapts learning rates for each parameter based on past gradients.\n\n```\n{\n    \"$type\": \"adagrad\",               # AdaGrad optimizer type\n    \"epsilon\": 1E-08                  # Small constant for numerical stability\n}\n```\n\n### Adam\nPopular optimizer that combines momentum and adaptive learning rates for fast convergence.\n\n```\n{\n    \"$type\": \"adam\",                  # Adam optimizer type\n    \"beta1\": 0.9,                     # Exponential decay rate for first moment\n    \"beta2\": 0.999,                   # Exponential decay rate for second moment\n    \"epsilon\": 1E-08                  # Small constant for numerical stability\n}\n```\n\n### RmsProp\nOptimizer that adjusts learning rate by dividing by a running average of gradients.\n\n```\n{\n    \"$type\": \"rmsprop\",               # RMSProp optimizer type\n    \"rho\": 0.1,                       # Decay rate for moving average of squared gradient\n    \"epsilon\": 1E-08                  # Small constant for numerical stability\n}\n```\n\n### Sgd\nStochastic Gradient Descent, a traditional optimizer using a fixed learning rate.\n\n```\n{\n    \"$type\": \"sgd\"                    # Stochastic Gradient Descent optimizer\n}\n```\n\n### SgdMomentum\nSGD variant that incorporates momentum to accelerate convergence.\n\n```\n{\n    \"$type\": \"sgdmomentum\",           # SGD with momentum optimizer type\n    \"momentum\": 0.1                   # Momentum factor to accelerate SGD\n}\n```\n\n## Learning rate schedulers\nAdjust learning rate dynamically during training.\n\n### Constant\nScheduler with a fixed learning rate across all training epochs.\n\n```\n{\n    \"$type\": \"constant\",              # Constant learning rate scheduler\n    \"lr\": 0.01                        # Fixed learning rate value\n}\n```\n\n### ExponentialDecay\nScheduler that gradually decreases learning rate exponentially over time.\n\n```\n{\n    \"$type\": \"exponential_decay\",     # Exponential decay scheduler\n    \"lr\": 0.01,                       # Initial learning rate\n    \"decay\": 0.05                     # Decay factor applied per epoch\n}\n```\n\n### StepDecay\nScheduler that reduces the learning rate at set intervals during training.\n\n```\n{\n    \"$type\": \"step_decay\",            # Step decay scheduler\n    \"lr\": 0.01,                       # Initial learning rate\n    \"step\": 10,                       # Epoch interval for decay\n    \"decay\": 0.5                      # Factor by which to decrease learning rate\n}\n```\n## Loss functions\nFunctions to calculate error between predicted and true labels.\n\n### CrossEntropyLoss\nLoss function used in classification tasks; compares model's predicted probabilities to true class labels.\n\n### Mse\nMean Squared Error loss function used in regression tasks; measures accuracy by averaging squared prediction errors.\n\n### Training Config\nDefines the training parameters and configuration for optimizing the neural network.\n\n```\n{\n  \"epochs\": 20,                     # Total number of training epochs or iterations over the dataset\n  \"lr_schedule\": {                  \n    \"$type\": \"exponential_decay\",   # Type of learning rate scheduler (e.g., exponential decay)\n    \"lr\": 0.001,                    # Initial learning rate to be used at the start of training\n    \"decay\": 0.05                   # Rate at which the learning rate decreases each epoch\n  },\n  \"optimizer\": {                    \n    \"$type\": \"adam\",                # Optimization algorithm type (e.g., Adam)\n    \"beta1\": 0.9,                   # Exponential decay rate for the first moment estimates (Adam)\n    \"beta2\": 0.999,                 # Exponential decay rate for the second moment estimates (Adam)\n    \"epsilon\": 1E-08                # Small constant for numerical stability in Adam optimizer\n  },\n  \"loss\": 0,                        # Loss function identifier (e.g., 0 for MSE, 1 for CrossEntropy)\n  \"batch\": 100                      # Size of each batch of data samples during training\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimmoth%2Fvcortex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimmoth%2Fvcortex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimmoth%2Fvcortex/lists"}