MCPcopy Create free account
hub / github.com/CodingBeard/tfkg / Fit

Method Fit

model/model.go:419–697  ·  view source on GitHub ↗
(
	dataset data.Dataset,
	config FitConfig,
)

Source from the content-addressed store, hash-verified

417}
418
419func (m *TfkgModel) Fit(
420 dataset data.Dataset,
421 config FitConfig,
422) {
423 trainSig := m.model.Signatures["learn"]
424 var trainOutputs []tf.Output
425 output := 0
426 for _, info := range trainSig.Outputs {
427 parts := strings.Split(info.Name, ":")
428 if len(parts) != 2 {
429 e := fmt.Errorf("error getting output for train signature in fit")
430 m.errorHandler.Error(e)
431 return
432 }
433 name := parts[0]
434 trainOutputs = append(trainOutputs, m.model.Graph.Operation(name).Output(output))
435 output++
436 }
437
438 if config.Epochs == 0 {
439 config.Epochs = 1
440 }
441
442 for i := range config.Metrics {
443 config.Metrics[i].Init()
444 }
445 for i := range config.Callbacks {
446 e := config.Callbacks[i].Init()
447 if e != nil {
448 m.errorHandler.Error(e)
449 return
450 }
451 }
452
453 for epoch := 1; epoch <= config.Epochs; epoch++ {
454
455 generatorChan := dataset.
456 SetMode(data.GeneratorModeTrain).
457 GeneratorChan(config.BatchSize, config.PreFetch)
458
459 labelOp := m.model.Graph.Operation(fmt.Sprintf("learn_%s", "y")).Output(0)
460 classWeightOp := m.model.Graph.Operation(fmt.Sprintf("learn_%s", "class_weights")).Output(0)
461
462 var inputOps []tf.Output
463 for offset := range dataset.GetColumnNames() {
464 inputOps = append(inputOps, m.model.Graph.Operation(fmt.Sprintf("learn_inputs_%d", offset)).Output(0))
465 }
466
467 halt := false
468
469 var trainLogs []callback.Log
470
471 batch := 1
472 totalBatches := dataset.Len() / config.BatchSize
473 trainTotalLoss := float64(0)
474 swg := sizedwaitgroup.New(runtime.NumCPU())
475 modelLock := &sync.Mutex{}
476 for generatorBatch := range generatorChan {

Callers 9

readFileNamesMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 9

getMetricLogsMethod · 0.95
processCallbacksMethod · 0.95
ErrorMethod · 0.65
InitMethod · 0.65
GeneratorChanMethod · 0.65
SetModeMethod · 0.65
GetColumnNamesMethod · 0.65
LenMethod · 0.65
ResetMethod · 0.65

Tested by

no test coverage detected