LoadSavedModel creates a new SavedModel from a model previously exported to a directory on disk. Exported models contain a set of graphs and, optionally, variable values. Tags in the model identify a single graph. LoadSavedModel initializes a session with the identified graph and with variables ini
(exportDir string, tags []string, options *SessionOptions)
| 46 | // See: |
| 47 | // https://www.tensorflow.org/code/tensorflow/python/saved_model/ |
| 48 | func LoadSavedModel(exportDir string, tags []string, options *SessionOptions) (*SavedModel, error) { |
| 49 | status := newStatus() |
| 50 | cOpt, doneOpt, err := options.c() |
| 51 | defer doneOpt() |
| 52 | if err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | cExportDir := C.CString(exportDir) |
| 56 | cTags := make([]*C.char, len(tags)) |
| 57 | for i := range tags { |
| 58 | cTags[i] = C.CString(tags[i]) |
| 59 | } |
| 60 | graph := NewGraph() |
| 61 | // TODO(jhseu): Add support for run_options and meta_graph_def. |
| 62 | cSess := C.TF_LoadSessionFromSavedModel(cOpt, nil, cExportDir, (**C.char)(unsafe.Pointer(&cTags[0])), C.int(len(cTags)), graph.c, nil, status.c) |
| 63 | for i := range cTags { |
| 64 | C.free(unsafe.Pointer(cTags[i])) |
| 65 | } |
| 66 | C.free(unsafe.Pointer(cExportDir)) |
| 67 | |
| 68 | if err := status.Err(); err != nil { |
| 69 | return nil, err |
| 70 | } |
| 71 | s := &Session{c: cSess} |
| 72 | runtime.SetFinalizer(s, func(s *Session) { s.Close() }) |
| 73 | return &SavedModel{Session: s, Graph: graph}, nil |
| 74 | } |