|
15 | 15 | import Foundation
|
16 | 16 | import ModelSupport
|
17 | 17 | import TensorFlow
|
| 18 | +import Datasets |
18 | 19 |
|
19 | 20 | let options = Options.parseOrExit()
|
20 | 21 |
|
21 |
| -let datasetFolder = URL(fileURLWithPath: options.datasetPath, isDirectory: true) |
22 |
| -let trainFolderA = datasetFolder.appendingPathComponent("trainA") |
23 |
| -let trainFolderB = datasetFolder.appendingPathComponent("trainB") |
24 |
| -let testFolderA = datasetFolder.appendingPathComponent("testA") |
25 |
| -let testFolderB = datasetFolder.appendingPathComponent("testB") |
| 22 | +let datasetFolder: URL |
| 23 | +let trainFolderA: URL |
| 24 | +let trainFolderB: URL |
| 25 | +let testFolderA: URL |
| 26 | +let testFolderB: URL |
| 27 | + |
| 28 | +if options.datasetPath.length != 0 { |
| 29 | + datasetFolder = URL(fileURLWithPath: options.datasetPath, isDirectory: true) |
| 30 | + trainFolderA = datasetFolder.appendingPathComponent("trainA") |
| 31 | + trainFolderB = datasetFolder.appendingPathComponent("trainB") |
| 32 | + testFolderA = datasetFolder.appendingPathComponent("testA") |
| 33 | + testFolderB = datasetFolder.appendingPathComponent("testB") |
| 34 | +} else { |
| 35 | + func downloadZebraDataSetIfNotPresent(to directory: URL) { |
| 36 | + let downloadPath = directory.appendingPathComponent("horse2zebra").path |
| 37 | + let directoryExists = FileManager.default.fileExists(atPath: downloadPath) |
| 38 | + let contentsOfDir = try? FileManager.default.contentsOfDirectory(atPath: downloadPath) |
| 39 | + let directoryEmpty = (contentsOfDir == nil) || (contentsOfDir!.isEmpty) |
| 40 | + |
| 41 | + guard !directoryExists || directoryEmpty else { return } |
| 42 | + |
| 43 | + let location = URL( |
| 44 | + string: "https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/horse2zebra.zip")! |
| 45 | + let _ = DatasetUtilities.downloadResource( |
| 46 | + filename: "horse2zebra", fileExtension: "zip", |
| 47 | + remoteRoot: location.deletingLastPathComponent(), localStorageDirectory: directory) |
| 48 | + } |
| 49 | + |
| 50 | + datasetFolder = DatasetUtilities.defaultDirectory.appendingPathComponent("CycleGAN", isDirectory: true) |
| 51 | + downloadZebraDataSetIfNotPresent(to: datasetFolder) |
| 52 | + trainFolderA = datasetFolder.appendingPathComponent("horse2zebra/trainA") |
| 53 | + trainFolderB = datasetFolder.appendingPathComponent("horse2zebra/trainB") |
| 54 | + testFolderA = datasetFolder.appendingPathComponent("horse2zebra/testA") |
| 55 | + testFolderB = datasetFolder.appendingPathComponent("horse2zebra/testB") |
| 56 | +} |
26 | 57 |
|
27 | 58 | let trainDatasetA = try Images(folderURL: trainFolderA)
|
28 | 59 | let trainDatasetB = try Images(folderURL: trainFolderB)
|
|
0 commit comments