[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
(broken)test[clari8] 10 training a TrainingModel
"Ensure Training set is ready"
Smalltalk at: #TrainingSet ifAbsent: [
self abortPage.
self error: 'Missing TrainingSet'.
]
"Rearrange the samples for training"
| map |
map := PoolDictionary new.
TrainingSet associationsDo: [:assoc| | concept |
concept := assoc key.
assoc value do: [:img| | id pool |
id := img isString ifTrue: [ img ] ifFalse: [ img localIdentifier asString ].
pool := map at: id ifAbsentPut: [ Array with: img ].
pool add: concept.
]
].
Smalltalk at: #TrainingSteps put: map values asArray.
"Creating a new model"
TrainingModel := CAIModel withId: 'test[clari8] model' name: 'test[clari8] model'.
self print: 'TrainingModel created'.
"Training the model"
| stampSize train step predict useAllSamples |
stampSize := 120.
useAllSamples := false.
train := [:tuple| | img concepts |
self print: '[' ,TrainingSteps size ,'] Traning ' ,tuple.
concepts := (tuple copyFrom: 2 to: tuple size)
collect: [:key| CAIConcept withId: key name: key ].
tuple first isString ifTrue: [
self print: '// instantiating CAIImage'.
img := CAIImage withURL: NSURL @ tuple first.
step value: img value: concepts.
] ifFalse: [
PHImageManager default
withImageForAsset: tuple first ofSize: CGSize @ stampSize
do: [:image :info|
img := CAIImage withImage: image.
step value: img value: concepts.
]
].
].
step := [:img :concepts| | dataAsset input |
self print: '// instantiating CAIDataAsset...'.
dataAsset := CAIDataAsset withImage: img.
self print: '// add concepts...'.
dataAsset addConcepts: concepts.
self print: '// instantiating CAIInput'.
input := CAIInput with: dataAsset.
self print: '// About to train model'.
TrainingModel
trainWithInputs: (NSArray withObject: input)
onSuccess: [ self print: '// OK - ' ,tuple ]
onError: [:nsError| self print: 'Error ' ,nsError description ].
self print: '// step done'.
].
[ TrainingSteps notEmpty ] whileTrue: [
train value: TrainingSteps removeFirst.
useAllSamples ifFalse: [ ^self print: '// useAllSamples=false' ].
].
self print: '// train complete'.