|
-
Jul 30th, 2024, 05:45 AM
#1
Thread Starter
New Member
Neural networks in VBA
If you guys have some experience from Pytorch or other major deep learning frameworks, and have some time to spare, give my simple neural network project (maybe the first one in VBA?) a test run. Big plus if you can test it with OpenBLAS dll which you put inside the same folder as the Excel workbook and edit the dll path in BlasFunctions module -- OpenBLAS provides prebuilt binary packages here https://sourceforge.net/projects/ope...files/v0.3.27/:
https://github.com/personalityson/VBANN
Code:
Public Sub SetupAndTrainSequential()
Const MODEL_NAME As String = "MySequentialModel"
Dim lBatchSize As Long
Dim lNumEpochs As Long
Dim lInputSize As Long
Dim lLabelSize As Long
Dim oFullSet As TensorDataset
Dim oTrainingSet As SubsetDataset
Dim oTrainingLoader As DataLoader
Dim oTestSet As SubsetDataset
Dim oTestLoader As DataLoader
Dim oModel As Sequential
lInputSize = 8
lLabelSize = 1
lBatchSize = 16
lNumEpochs = 40
'Prepare training data
Set oFullSet = ImportDatasetFromWorksheet(ThisWorkbook, "Concrete", Array(lInputSize, lLabelSize), True, False)
RandomSplit oFullSet, 0.8, oTrainingSet, oTestSet
Set oTrainingLoader = DataLoader(oTrainingSet, lBatchSize)
Set oTestLoader = DataLoader(oTestSet, lBatchSize)
'Setup and train
Set oModel = Sequential(L2Loss(), SGDM())
oModel.Add InputNormalizationLayer(oTrainingLoader)
oModel.Add FullyConnectedLayer(lInputSize, 32)
oModel.Add LeakyReLULayer()
oModel.Add FullyConnectedLayer(32, 16)
oModel.Add LeakyReLULayer()
oModel.Add FullyConnectedLayer(16, 8)
oModel.Add LeakyReLULayer()
oModel.Add FullyConnectedLayer(8, lLabelSize)
oModel.Fit oTrainingLoader, oTestLoader, lNumEpochs
'Compute test loss
MsgBox oModel.Loss(oTestLoader)
'Save to worksheet
Serialize MODEL_NAME, oModel
'Load from worksheet
Set oModel = Unserialize(MODEL_NAME)
'Compute test loss again with unserialized model
MsgBox oModel.Loss(oTestLoader)
Beep
End Sub
Public Sub SetupAndTrainXGBoost()
Const MODEL_NAME As String = "MyXGBoostModel"
Dim lInputSize As Long
Dim lLabelSize As Long
Dim lNumRounds As Long
Dim lMaxDepth As Long
Dim dblLearningRate As Double
Dim X As Tensor
Dim T As Tensor
Dim oFullSet As TensorDataset
Dim oTrainingSet As SubsetDataset
Dim oTestSet As SubsetDataset
Dim oModel As XGBoost
lInputSize = 8
lLabelSize = 1
dblLearningRate = 0.1
lMaxDepth = 6
lNumRounds = 100
'Prepare training data
Set oFullSet = ImportDatasetFromWorksheet(ThisWorkbook, "Concrete", Array(lInputSize, lLabelSize), True, True)
RandomSplit oFullSet, 0.8, oTrainingSet, oTestSet
Set X = oTrainingSet.Cache.Tensor(1)
Set T = oTrainingSet.Cache.Tensor(2)
'Setup and train
Set oModel = XGBoost(L2Loss(), dblLearningRate, lMaxDepth)
oModel.Fit X, T, lNumRounds
'Compute test loss
Set X = oTestSet.Cache.Tensor(1)
Set T = oTestSet.Cache.Tensor(2)
MsgBox oModel.Loss(X, T)
'Save to worksheet
Serialize MODEL_NAME, oModel
'Load from worksheet
Set oModel = Unserialize(MODEL_NAME)
'Compute test loss again with unserialized model
MsgBox oModel.Loss(X, T)
Beep
End Sub
Thanks
Last edited by drgs; Aug 2nd, 2025 at 04:36 PM.
-
Aug 17th, 2024, 09:13 AM
#2
Re: Neural networks in VBA
Hi
I am interested in NN.
I have implemented a simple one in VB6 that can evolve using backpropagation or Neuroevolution. (all from scratch)
https://www.vbforums.com/showthread....Neural-Network
I would like to try yours because I think it is more advanced (Deep). And maybe it could also be used for "style transfer" on images.
I have (sort of) never worked in VBA, so, do you have a VB6 version ?
-
Aug 17th, 2024, 03:57 PM
#3
Thread Starter
New Member
Re: Neural networks in VBA
 Originally Posted by reexre
Hi
I am interested in NN.
I have implemented a simple one in VB6 that can evolve using backpropagation or Neuroevolution. (all from scratch)
https://www.vbforums.com/showthread....Neural-Network
I would like to try yours because I think it is more advanced (Deep). And maybe it could also be used for "style transfer" on images.
I have (sort of) never worked in VBA, so, do you have a VB6 version ?
Hi,
For me it is the opposite -- I have never worked with VB6. I do rely on saving models to worksheets and reading data from worksheets, so I guess it won't work without modifications.
I only have very basic layers to put together a MLP, but by its modular design it's only a matter of adding new layer classes...
(Currently I'm trying to integrate an extra dll for vector math (Intel Performance Primitives) to speed things up, so I ended up rewriting a few thing.)
For style transfer on images you need at least convolutional layers + pooling layers, I think. Plus, a way to read images from disc, with color channels and everything.
It's possible, but not really what I intended it for
Btw, curious to have a peek at your code, but cant seem to find any source...
Last edited by drgs; Aug 17th, 2024 at 04:20 PM.
-
Aug 18th, 2024, 01:06 PM
#4
Re: Neural networks in VBA
Thank you for reply
 Originally Posted by drgs
...
Btw, curious to have a peek at your code, but cant seem to find any source...
it's in the #2 post NNandGA.zip
-
Jul 15th, 2025, 10:32 AM
#5
New Member
Re: Neural networks in VBA
 Originally Posted by drgs
If you guys have some experience from Pytorch or other major deep learning frameworks, and have some time to spare, give my simple neural network project (maybe the first one in VBA?) a test run. Big plus if you can test it with OpenBLAS dll which you put inside the same folder as the Excel workbook and edit the dll path in BlasFunctions module -- OpenBLAS provides prebuilt binary packages here https://sourceforge.net/projects/ope...files/v0.3.27/:
https://github.com/personalityson/VBANN
Interesting approaching...
I try to test the openBlas option but it don't work or I couldn't do it to work. 
The last procedure before crash is this
https://imgur.com/a/R52H6eK
What I'm missing? 
I'm using Office 2019 on Windows 7 x86
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|