(argv)
| 73 | |
| 74 | |
| 75 | def main(argv): |
| 76 | # If you previously ran this app with an earlier version of the API |
| 77 | # or if you change the list of scopes below, revoke your app's permission |
| 78 | # here: https://accounts.google.com/IssuedAuthSubTokens |
| 79 | # Then re-run the app to re-authorize it. |
| 80 | service, flags = sample_tools.init( |
| 81 | argv, |
| 82 | "prediction", |
| 83 | "v1.6", |
| 84 | __doc__, |
| 85 | __file__, |
| 86 | parents=[argparser], |
| 87 | scope=( |
| 88 | "https://www.googleapis.com/auth/prediction", |
| 89 | "https://www.googleapis.com/auth/devstorage.read_only", |
| 90 | ), |
| 91 | ) |
| 92 | |
| 93 | try: |
| 94 | # Get access to the Prediction API. |
| 95 | papi = service.trainedmodels() |
| 96 | |
| 97 | # List models. |
| 98 | print_header("Fetching list of first ten models") |
| 99 | result = papi.list(maxResults=10, project=flags.project_id).execute() |
| 100 | print("List results:") |
| 101 | pprint.pprint(result) |
| 102 | |
| 103 | # Start training request on a data set. |
| 104 | print_header("Submitting model training request") |
| 105 | body = {"id": flags.model_id, "storageDataLocation": flags.object_name} |
| 106 | start = papi.insert(body=body, project=flags.project_id).execute() |
| 107 | print("Training results:") |
| 108 | pprint.pprint(start) |
| 109 | |
| 110 | # Wait for the training to complete. |
| 111 | print_header("Waiting for training to complete") |
| 112 | while True: |
| 113 | status = papi.get(id=flags.model_id, project=flags.project_id).execute() |
| 114 | state = status["trainingStatus"] |
| 115 | print("Training state: " + state) |
| 116 | if state == "DONE": |
| 117 | break |
| 118 | elif state == "RUNNING": |
| 119 | time.sleep(SLEEP_TIME) |
| 120 | continue |
| 121 | else: |
| 122 | raise Exception("Training Error: " + state) |
| 123 | |
| 124 | # Job has completed. |
| 125 | print("Training completed:") |
| 126 | pprint.pprint(status) |
| 127 | break |
| 128 | |
| 129 | # Describe model. |
| 130 | print_header("Fetching model description") |
| 131 | result = papi.analyze(id=flags.model_id, project=flags.project_id).execute() |
| 132 | print("Analyze results:") |
no test coverage detected
searching dependent graphs…