Last active
December 14, 2020 11:13
-
-
Save followthemoney1/926965bd5315f0c5ea015bd67cc17b72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// datasetName = test_dev | |
static Future<void> generateLabels(String datasetName) async { | |
//const FUNCTIONS_URL = "us-central1-testproject-afd2f.cloudfunctions.net"; | |
final response = await http.get(Uri.https( | |
FUNCTIONS_URL, "/generateLabelFile", {"dataset": datasetName})); | |
if (response.statusCode == 200) { | |
return Future.value(); | |
} else { | |
throw Exception("Error while generating label file: " + response.body); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//datasetName = test_dev | |
//automlId = ICN5867432750952218624 | |
static Future<String> importDataset( | |
String datasetName, String automlId) async { | |
//const FUNCTIONS_URL = "us-central1-testproject-afd2f.cloudfunctions.net"; | |
//_AUTOMLAPI = "/automlApi" | |
final response = await http.post( | |
Uri.https(FUNCTIONS_URL, "$_AUTOMLAPI/import"), | |
body: { | |
"name": datasetName, | |
"datasetId": automlId, | |
"labels": "labels.csv" | |
}, | |
); | |
if (response.statusCode == 200) { | |
if (response.body.isNotEmpty) { | |
final Map body = jsonDecode(response.body); | |
print("Got response" + body.toString()); | |
return body["name"]; | |
} | |
} else { | |
throw Exception( | |
"Error while initiating importing the dataset: " + response.body); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// Training the dataset comprises of a set of steps | |
/// 1. Generate the labels.csv file | |
/// 2. Import the data into AutoML | |
/// 3. Initiate training the model | |
/// 4. Export the model into GCS | |
/// | |
/// All of these (apart from 1) returns long-running operations from AutoML. | |
/// | |
Future<void> _initTraining(BuildContext context, int trainingBudget) async { | |
//final datasetName = widget.dataset.name.trim(); | |
final datasetName = "test_dev"; | |
try { | |
await generateLabels(datasetName); | |
final importDatasetOperation = | |
await importDataset(datasetName, widget.dataset.automlId); // widget.dataset.automlId = ICN5867432750952218624 | |
Firestore.instance.collection('operations').add({ | |
"dataset_id": ICN5867432750952218624, // ICN5867432750952218624 | |
"name": importDatasetOperation, // имя которое получил с этой функции | |
"last_updated": DateTime.now().millisecondsSinceEpoch, | |
"done": false, | |
"training_budget": 1, | |
"type": "IMPORT_DATA" | |
}).whenComplete(() { | |
print("Added operation: $importDatasetOperation to Firestore"); | |
}); | |
} catch (err) { | |
showSnackBar("Error while starting training"); | |
print("Error $err"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment