(dir string)
| 964 | } |
| 965 | |
| 966 | func (m *TfkgModel) Save(dir string) error { |
| 967 | signatureCount := len(m.model.Signatures) |
| 968 | |
| 969 | e := os.MkdirAll(filepath.Join(dir, "variables"), os.ModePerm) |
| 970 | if e != nil { |
| 971 | m.errorHandler.Error(e) |
| 972 | return e |
| 973 | } |
| 974 | |
| 975 | if len(m.cpuPbCache) > 0 { |
| 976 | e = ioutil.WriteFile(filepath.Join(dir, "saved_model.pb"), m.cpuPbCache, os.ModePerm) |
| 977 | if e != nil { |
| 978 | m.errorHandler.Error(e) |
| 979 | return e |
| 980 | } |
| 981 | } else { |
| 982 | e = ioutil.WriteFile(filepath.Join(dir, "saved_model.pb"), m.pbCache, os.ModePerm) |
| 983 | if e != nil { |
| 984 | m.errorHandler.Error(e) |
| 985 | return e |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | filenameInput, e := tf.NewTensor(filepath.Join(dir, "variables/variables")) |
| 990 | if e != nil { |
| 991 | m.errorHandler.Error(e) |
| 992 | return e |
| 993 | } |
| 994 | |
| 995 | _, e = m.model.Session.Run( |
| 996 | map[tf.Output]*tf.Tensor{ |
| 997 | m.model.Graph.Operation("saver_filename").Output(0): filenameInput, |
| 998 | }, |
| 999 | []tf.Output{ |
| 1000 | m.model.Graph.Operation(fmt.Sprintf("StatefulPartitionedCall_%d", signatureCount-1)).Output(0), |
| 1001 | }, |
| 1002 | nil, |
| 1003 | ) |
| 1004 | if e != nil { |
| 1005 | m.errorHandler.Error(e) |
| 1006 | return e |
| 1007 | } |
| 1008 | |
| 1009 | e = ioutil.WriteFile(filepath.Join(dir, "tfkg-version"), []byte(Version), os.ModePerm) |
| 1010 | if e != nil { |
| 1011 | m.errorHandler.Error(e) |
| 1012 | return e |
| 1013 | } |
| 1014 | |
| 1015 | return nil |
| 1016 | } |
| 1017 | |
| 1018 | type pythonConfig struct { |
| 1019 | ModelConfig string `json:"model_config"` |
no test coverage detected