📄 classtraininginstance.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "classTrainingInstance"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Public NoOfInputs As Integer
Public NoOfOutputs As Integer
Public TrainingError As Single
Dim inputs() As Single
Dim outputs() As Single
Public imageWidth As Integer
Public imageHeight As Integer
Public Sub init(No_Of_Inputs As Integer, No_Of_Outputs As Integer)
imageWidth = 0
imageHeight = 0
NoOfInputs = No_Of_Inputs
NoOfOutputs = No_Of_Outputs
ReDim inputs(NoOfInputs)
ReDim outputs(NoOfOutputs)
End Sub
Public Sub initImage(img As classImageProcessing, No_Of_Outputs As Integer)
imageWidth = img.width
imageHeight = img.height
NoOfInputs = imageWidth * imageHeight
NoOfOutputs = No_Of_Outputs
ReDim inputs(NoOfInputs)
ReDim outputs(NoOfOutputs)
Call setImage(img)
End Sub
Public Sub setInput(index As Integer, value As Single)
inputs(index) = value
End Sub
Public Function getInput(index As Integer) As Single
getInput = inputs(index)
End Function
Public Sub setOutput(index As Integer, value As Single)
outputs(index) = value
End Sub
Public Function getOutput(index As Integer) As Single
getOutput = outputs(index)
End Function
Public Sub setImage(img As classImageProcessing)
'loads in image into the inputs array
Dim x As Integer
Dim y As Integer
Dim i As Integer
i = 0
For x = 0 To img.width - 1
For y = 0 To img.height - 1
inputs(i) = img.getPoint(x, y) / 255
i = i + 1
Next
Next
End Sub
Public Sub getImage(img As classImageProcessing)
'gets the image stored within the inputs array
Dim x As Integer
Dim y As Integer
Dim i As Integer
i = 0
For x = 0 To imageWidth - 1
For y = 0 To imageHeight - 1
Call img.setPoint(x, y, CInt(inputs(i) * 255))
i = i + 1
Next
Next
End Sub
Public Sub setClassification(classificationID As Integer)
'sets the unique classification
Dim i As Integer
For i = 0 To NoOfOutputs
If (i <> classificationID) Then
outputs(i) = 0.1
Else
outputs(i) = 0.9
End If
Next
End Sub
Public Sub save(fileNumber As Integer)
Dim i As Integer
Dim n As Integer
Print #fileNumber, "[Training Instance]"
Print #fileNumber, NoOfInputs
Print #fileNumber, NoOfOutputs
Print #fileNumber, TrainingError
Print #fileNumber, imageWidth
Print #fileNumber, imageHeight
n = 0
For i = 0 To NoOfInputs - 1
Print #fileNumber, inputs(i) & ", ";
If (n >= imageWidth) Then
n = 0
Print #fileNumber, " "
End If
n = n + 1
Next
For i = 0 To NoOfOutputs - 1
Print #fileNumber, outputs(i)
Next
End Sub
Public Sub load(fileNumber As Integer)
Dim i As Integer
Dim dummy As String
Input #fileNumber, dummy
Input #fileNumber, NoOfInputs
Input #fileNumber, NoOfOutputs
Input #fileNumber, TrainingError
Input #fileNumber, imageWidth
Input #fileNumber, imageHeight
Call init(NoOfInputs, NoOfOutputs)
For i = 0 To NoOfInputs - 1
Input #fileNumber, inputs(i)
Next
For i = 0 To NoOfOutputs - 1
Input #fileNumber, outputs(i)
Next
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -