[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

test[clari8] 11 predicting with TrainingModel



"Ensure Training model is ready"
Smalltalk at: #TrainingModel ifAbsent: [
	self abortPage.
	self error: 'Missing TrainingModel'.
]


"Training complete - Accessing the trained model"
| model obj |
model := TrainingModel.
#(	modelId name
	createdAt createdDate
	output version appId
) do: [:selector|
	self print: selector,': '
		,(model perform: selector) toString
].


"Predicting on Google Photos"
| predict |
predict := [:url :tags| | image dataAsset input inputs result |
	image := CAIImage withURL: NSURL @ url.
	dataAsset := CAIDataAsset withImage: image.
	input := CAIInput withDataAsset: dataAsset.
	inputs := NSArray withObject: input.
	TrainingModel
		predict: inputs
		conceptNames: [:array| self print: array toString "sayIn: #en-US",' vs. ' ,tags ]
		onError: [:nsError| self error: nsError ].
].
self print: '// testing model with Google Photos...'.
GooglePhotos do: [:tuple| predict value: tuple first value: tuple last ]