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

Method CompileAndLoad

model/model.go:1036–1202  ·  view source on GitHub ↗
(config CompileConfig, sessionOptions ...*for_core_protos_go_proto.ConfigProto)

Source from the content-addressed store, hash-verified

1034}
1035
1036func (m *TfkgModel) CompileAndLoad(config CompileConfig, sessionOptions ...*for_core_protos_go_proto.ConfigProto) error {
1037 if config.Loss == "" {
1038 config.Loss = LossMSE
1039 }
1040 if config.Optimizer == nil {
1041 config.Optimizer = optimizer.Adam()
1042 }
1043 if config.BatchSize == 0 {
1044 config.BatchSize = 1
1045 }
1046 m.logger.InfoF("model", "Compiling and loading model. If anything goes wrong python error messages will be printed out.")
1047 m.modelDefinitionSaveDir = config.ModelInfoSaveDir
1048 modelConfig, e := m.generateKerasDefinitionJson()
1049 if e != nil {
1050 return e
1051 }
1052
1053 tempDir := filepath.Join(os.TempDir(), "/tfkg")
1054
1055 e = os.MkdirAll(tempDir, os.ModePerm)
1056 if e != nil {
1057 m.errorHandler.Error(e)
1058 return e
1059 }
1060
1061 if config.ModelInfoSaveDir != "" {
1062 indentedJson := bytes.NewBuffer([]byte{})
1063 e = json.Indent(indentedJson, []byte(modelConfig), "", " ")
1064 if e != nil {
1065 m.errorHandler.Error(e)
1066 return e
1067 }
1068 e = ioutil.WriteFile(filepath.Join(config.ModelInfoSaveDir, "model.json"), indentedJson.Bytes(), os.ModePerm)
1069 if e != nil {
1070 m.errorHandler.Error(e)
1071 return e
1072 }
1073 }
1074
1075 pConfig := pythonConfig{
1076 ModelConfig: modelConfig,
1077 SaveDir: filepath.Join(tempDir, tempModelDir),
1078 ModelDefinitionSaveDir: config.ModelInfoSaveDir,
1079 Loss: string(config.Loss),
1080 Optimizer: config.Optimizer.GetKerasLayerConfig(),
1081 BatchSize: config.BatchSize,
1082 CpuInference: config.CpuInference,
1083 }
1084
1085 configBytes, e := json.Marshal(pConfig)
1086 if e != nil {
1087 m.errorHandler.Error(e)
1088 return e
1089 }
1090
1091 ignoreRegex := regexp.MustCompile("# tfkg-ignore.*# tfkg-ignore-end")
1092
1093 layerTypesDefined := make(map[string]bool)

Callers 8

mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80

Calls 11

GetLayerWeightsMethod · 0.95
SetModelWeightsMethod · 0.95
AdamFunction · 0.92
GetTfkgPythonCodeFunction · 0.85
InfoFMethod · 0.65
ErrorMethod · 0.65
GetKerasLayerConfigMethod · 0.65
GetLayerWeightsMethod · 0.65
GetNameMethod · 0.65

Tested by

no test coverage detected