| 219 | } |
| 220 | |
| 221 | func modelFiles(dir string) (modelfile, labelsfile string, err error) { |
| 222 | const URL = "https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip" |
| 223 | var ( |
| 224 | model = filepath.Join(dir, "tensorflow_inception_graph.pb") |
| 225 | labels = filepath.Join(dir, "imagenet_comp_graph_label_strings.txt") |
| 226 | zipfile = filepath.Join(dir, "inception5h.zip") |
| 227 | ) |
| 228 | if filesExist(model, labels) == nil { |
| 229 | return model, labels, nil |
| 230 | } |
| 231 | log.Println("Did not find model in", dir, "downloading from", URL) |
| 232 | if err := os.MkdirAll(dir, 0755); err != nil { |
| 233 | return "", "", err |
| 234 | } |
| 235 | if err := download(URL, zipfile); err != nil { |
| 236 | return "", "", fmt.Errorf("failed to download %v - %v", URL, err) |
| 237 | } |
| 238 | if err := unzip(dir, zipfile); err != nil { |
| 239 | return "", "", fmt.Errorf("failed to extract contents from model archive: %v", err) |
| 240 | } |
| 241 | os.Remove(zipfile) |
| 242 | return model, labels, filesExist(model, labels) |
| 243 | } |
| 244 | |
| 245 | func filesExist(files ...string) error { |
| 246 | for _, f := range files { |