( errorHandler *cberrors.ErrorsContainer, logger *cblog.Logger, dir string, loss Loss, optimizer optimizer.Optimizer, sessionOptions ...*for_core_protos_go_proto.ConfigProto, )
| 175 | } |
| 176 | |
| 177 | func LoadVanillaModel( |
| 178 | errorHandler *cberrors.ErrorsContainer, |
| 179 | logger *cblog.Logger, |
| 180 | dir string, |
| 181 | loss Loss, |
| 182 | optimizer optimizer.Optimizer, |
| 183 | sessionOptions ...*for_core_protos_go_proto.ConfigProto, |
| 184 | ) (*TfkgModel, error) { |
| 185 | logger.InfoF("model", "Loading vanilla model. If anything goes wrong python error messages will be printed out.") |
| 186 | |
| 187 | tempDir := filepath.Join(os.TempDir(), "/tfkg") |
| 188 | |
| 189 | e := os.MkdirAll(tempDir, os.ModePerm) |
| 190 | if e != nil { |
| 191 | errorHandler.Error(e) |
| 192 | return nil, e |
| 193 | } |
| 194 | |
| 195 | config := vanillaPythonConfig{ |
| 196 | ModelDir: dir, |
| 197 | SaveDir: filepath.Join(tempDir, tempModelDir), |
| 198 | Loss: string(loss), |
| 199 | Optimizer: optimizer.GetKerasLayerConfig(), |
| 200 | } |
| 201 | |
| 202 | configBytes, e := json.Marshal(config) |
| 203 | if e != nil { |
| 204 | errorHandler.Error(e) |
| 205 | return nil, e |
| 206 | } |
| 207 | |
| 208 | tempPythonPath := filepath.Join(tempDir, "tfkg_create_model.py") |
| 209 | |
| 210 | e = ioutil.WriteFile(tempPythonPath, []byte(GetVanillaPythonCode()), os.ModePerm) |
| 211 | if e != nil { |
| 212 | errorHandler.Error(e) |
| 213 | return nil, e |
| 214 | } |
| 215 | defer os.Remove(tempPythonPath) |
| 216 | |
| 217 | tempConfigPath := filepath.Join(tempDir, "tfkg_config.json") |
| 218 | |
| 219 | e = ioutil.WriteFile(tempConfigPath, configBytes, os.ModePerm) |
| 220 | if e != nil { |
| 221 | errorHandler.Error(e) |
| 222 | return nil, e |
| 223 | } |
| 224 | defer os.Remove(tempPythonPath) |
| 225 | |
| 226 | cmd := exec.Command("python", tempPythonPath, tempConfigPath) |
| 227 | output, e := cmd.CombinedOutput() |
| 228 | if e != nil { |
| 229 | errorHandler.Error(e) |
| 230 | } |
| 231 | fmt.Println(string(output)) |
| 232 | if e != nil { |
| 233 | return nil, e |
| 234 | } |
no test coverage detected