Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit cbc8be7

Browse files
committed
Don't store video_uuids as json in action parameters for dataset producer. Use a list.
1 parent 30b3e2c commit cbc8be7

File tree

5 files changed

+29
-30
lines changed

5 files changed

+29
-30
lines changed

server/app_engine.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -837,10 +837,10 @@ def can_delete_videos():
837837
team_uuid = team_info.retrieve_team_uuid(flask.session, flask.request)
838838
data = validate_keys(flask.request.form.to_dict(flat=True),
839839
['video_uuids'])
840-
video_uuids_json = storage.validate_uuids_json(data.get('video_uuids'))
840+
video_uuids = storage.validate_uuids_json(data.get('video_uuids'))
841841
# storage.can_delete_videos will raise HttpErrorNotFound
842842
# if any of the team_uuid/video_uuid is not found.
843-
can_delete_videos, messages = storage.can_delete_videos(team_uuid, video_uuids_json)
843+
can_delete_videos, messages = storage.can_delete_videos(team_uuid, video_uuids)
844844
response = {
845845
'can_delete_videos': can_delete_videos,
846846
'messages': messages,
@@ -1068,7 +1068,7 @@ def prepare_to_start_dataset_production():
10681068
'message': 'The Description is not valid or is a duplicate.'
10691069
}
10701070
return flask.jsonify(__sanitize(response))
1071-
video_uuids_json = storage.validate_uuids_json(data.get('video_uuids'))
1071+
video_uuids = storage.validate_uuids_json(data.get('video_uuids'))
10721072
try:
10731073
# The following min/max number (0 and 90) should match the min/max values in root.html.
10741074
eval_percent = validate_float(data.get('eval_percent'), min=0, max=90)
@@ -1093,9 +1093,9 @@ def prepare_to_start_dataset_production():
10931093
# dataset_producer.prepare_to_start_dataset_production will raise HttpErrorNotFound
10941094
# if any of the team_uuid/video_uuids is not found or if none of the videos have labeled frames.
10951095
dataset_uuid = dataset_producer.prepare_to_start_dataset_production(
1096-
team_uuid, description, video_uuids_json, eval_percent, create_time_ms)
1096+
team_uuid, description, video_uuids, eval_percent, create_time_ms)
10971097
action_parameters = dataset_producer.make_action_parameters(
1098-
team_uuid, dataset_uuid, video_uuids_json, eval_percent, create_time_ms)
1098+
team_uuid, dataset_uuid, video_uuids, eval_percent, create_time_ms)
10991099
action.trigger_action_via_blob(action_parameters)
11001100
response = {
11011101
'dataset_uuid': dataset_uuid,
@@ -1147,10 +1147,10 @@ def can_delete_datasets():
11471147
team_uuid = team_info.retrieve_team_uuid(flask.session, flask.request)
11481148
data = validate_keys(flask.request.form.to_dict(flat=True),
11491149
['dataset_uuids'])
1150-
dataset_uuids_json = storage.validate_uuids_json(data.get('dataset_uuids'))
1150+
dataset_uuids = storage.validate_uuids_json(data.get('dataset_uuids'))
11511151
# storage.can_delete_datasets will raise HttpErrorNotFound
11521152
# if any of the team_uuid/dataset_uuid is not found.
1153-
can_delete_datasets, messages = storage.can_delete_datasets(team_uuid, dataset_uuids_json)
1153+
can_delete_datasets, messages = storage.can_delete_datasets(team_uuid, dataset_uuids)
11541154
response = {
11551155
'can_delete_datasets': can_delete_datasets,
11561156
'messages': messages,
@@ -1245,7 +1245,7 @@ def start_training_model():
12451245
# description = validate_description(data.get('description'),
12461246
# other_descriptions=[m['description'] for m in storage.retrieve_model_list(team_uuid)])
12471247
description = validate_description(data.get('description'))
1248-
dataset_uuids_json = storage.validate_uuids_json(data.get('dataset_uuids'))
1248+
dataset_uuids = storage.validate_uuids_json(data.get('dataset_uuids'))
12491249
starting_model = model_trainer.validate_starting_model(data.get('starting_model'))
12501250
max_running_minutes = validate_positive_float(data.get('max_running_minutes'))
12511251
num_training_steps = validate_int(data.get('num_training_steps'),
@@ -1259,7 +1259,7 @@ def start_training_model():
12591259
# if the sorted_label_list values for all the datasets are not the same.
12601260
# model_trainer.start_training_model will raise HttpErrorUnprocessableEntity
12611261
# if the max_running_minutes exceeds the team's remaining_training_minutes.
1262-
model_entity = model_trainer.start_training_model(team_uuid, description, dataset_uuids_json,
1262+
model_entity = model_trainer.start_training_model(team_uuid, description, dataset_uuids,
12631263
starting_model, max_running_minutes, num_training_steps, create_time_ms, config.config[KEY_USE_TPU])
12641264
# Retrieve the team entity so the client gets the updated remaining_training_minutes.
12651265
team_entity = storage.retrieve_team_entity(team_uuid)
@@ -1427,10 +1427,10 @@ def can_delete_models():
14271427
team_uuid = team_info.retrieve_team_uuid(flask.session, flask.request)
14281428
data = validate_keys(flask.request.form.to_dict(flat=True),
14291429
['model_uuids'])
1430-
model_uuids_json = storage.validate_uuids_json(data.get('model_uuids'))
1430+
model_uuids = storage.validate_uuids_json(data.get('model_uuids'))
14311431
# storage.can_delete_models will raise HttpErrorNotFound
14321432
# if any of the team_uuid/model_uuid is not found.
1433-
can_delete_models, messages = storage.can_delete_models(team_uuid, model_uuids_json)
1433+
can_delete_models, messages = storage.can_delete_models(team_uuid, model_uuids)
14341434
response = {
14351435
'can_delete_models': can_delete_models,
14361436
'messages': messages,

server/blob_storage.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
# Python Standard Library
1818
from datetime import datetime, timedelta
19-
import json
2019
import logging
2120
import re
2221
import time

server/dataset_producer.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,42 @@
5050
'video_filename', 'frame_number', 'filename', 'image', 'format', 'bboxes_text'])
5151

5252

53-
def prepare_to_start_dataset_production(team_uuid, description, video_uuids_json, eval_percent, create_time_ms):
53+
def prepare_to_start_dataset_production(team_uuid, description, video_uuid_list, eval_percent, create_time_ms):
5454
# storage.prepare_to_start_dataset_production will raise HttpErrorNotFound
5555
# if any of the team_uuid/video_uuids is not found or if none of the videos have labeled frames.
5656
dataset_uuid = storage.prepare_to_start_dataset_production(team_uuid, description,
57-
json.loads(video_uuids_json), eval_percent, create_time_ms)
57+
video_uuid_list, eval_percent, create_time_ms)
5858
return dataset_uuid
5959

60-
def make_action_parameters(team_uuid, dataset_uuid, video_uuids_json, eval_percent, create_time_ms):
60+
def make_action_parameters(team_uuid, dataset_uuid, video_uuid_list, eval_percent, create_time_ms):
6161
action_parameters = action.create_action_parameters(
6262
team_uuid, action.ACTION_NAME_DATASET_PRODUCE)
6363
action_parameters['team_uuid'] = team_uuid
6464
action_parameters['dataset_uuid'] = dataset_uuid
65-
action_parameters['video_uuids_json'] = video_uuids_json
65+
action_parameters['video_uuid_list'] = video_uuid_list
6666
action_parameters['eval_percent'] = eval_percent
6767
action_parameters['create_time_ms'] = create_time_ms
6868
return action_parameters
6969

7070
def produce_dataset(action_parameters):
7171
team_uuid = action_parameters['team_uuid']
7272
dataset_uuid = action_parameters['dataset_uuid']
73-
video_uuids_json = action_parameters['video_uuids_json']
73+
if 'video_uuids_json' in action_parameters:
74+
video_uuids_json = action_parameters['video_uuids_json']
75+
video_uuid_list = json.loads(video_uuids_json)
76+
else:
77+
video_uuid_list = action_parameters['video_uuid_list']
7478
eval_percent = action_parameters['eval_percent']
7579
create_time_ms = action_parameters['create_time_ms']
7680

77-
video_uuid_list = json.loads(video_uuids_json)
7881
if len(video_uuid_list) == 0:
7982
message = "Error: No videos to process."
8083
logging.critical(message)
8184
raise exceptions.HttpErrorBadRequest(message)
8285

8386
video_entities = storage.retrieve_video_entities(team_uuid, video_uuid_list)
8487
if len(video_entities) != len(video_uuid_list):
85-
message = 'Error: One or more videos not found for video_uuids=%s.' % video_uuids_json
88+
message = 'Error: One or more videos not found for video_uuids=%s.' % str(video_uuid_list)
8689
logging.critical(message)
8790
raise exceptions.HttpErrorNotFound(message)
8891

server/model_trainer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __get_num_warmup_steps(original_starting_model, checkpoint_every_n, num_trai
129129
starting_model_data = STARTING_MODELS[original_starting_model]
130130
return min(starting_model_data['num_warmup_steps'], num_training_steps)
131131

132-
def start_training_model(team_uuid, description, dataset_uuids_json,
132+
def start_training_model(team_uuid, description, dataset_uuid_list,
133133
starting_model, max_running_minutes, num_training_steps, create_time_ms, use_tpu):
134134
found_starting_model = starting_model in STARTING_MODELS
135135
if found_starting_model:
@@ -167,10 +167,9 @@ def start_training_model(team_uuid, description, dataset_uuids_json,
167167
if fine_tune_checkpoint.endswith('.index'):
168168
fine_tune_checkpoint = fine_tune_checkpoint[:-6]
169169

170-
dataset_uuid_list = json.loads(dataset_uuids_json)
171170
dataset_entities = storage.retrieve_dataset_entities(team_uuid, dataset_uuid_list)
172171
if len(dataset_entities) != len(dataset_uuid_list):
173-
message = 'Error: One or more datasets not found for dataset_uuids=%s.' % dataset_uuids_json
172+
message = 'Error: One or more datasets not found for dataset_uuids=%s.' % str(dataset_uuid_list)
174173
logging.critical(message)
175174
raise exceptions.HttpErrorNotFound(message)
176175

server/storage.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ def validate_uuid(s):
6363

6464
def validate_uuids_json(s):
6565
try:
66-
for u in json.loads(s):
66+
l = json.loads(s)
67+
for u in l:
6768
validate_uuid(u)
6869
except:
6970
message = "Error: '%s' is not a valid argument." % s
7071
logging.critical(message)
7172
raise exceptions.HttpErrorBadRequest(message)
72-
return s
73+
return l
7374

7475
# teams - public methods
7576

@@ -392,10 +393,9 @@ def retrieve_video_entity_for_labeling(team_uuid, video_uuid):
392393
transaction.delete(tracker_client_entity.key)
393394
return video_entity
394395

395-
def can_delete_videos(team_uuid, video_uuids_json):
396+
def can_delete_videos(team_uuid, video_uuid_requested_list):
396397
can_delete_videos = True
397398
messages = []
398-
video_uuid_requested_list = json.loads(video_uuids_json)
399399
all_video_entities = retrieve_video_list(team_uuid)
400400
# Build a list of the video uuids that we found.
401401
video_uuids_found_list = []
@@ -1657,10 +1657,9 @@ def retrieve_model_list(team_uuid):
16571657
model_entity['model_folder'] = blob_storage.get_old_model_folder(team_uuid, model_entity['model_uuid'])
16581658
return model_entities
16591659

1660-
def can_delete_datasets(team_uuid, dataset_uuids_json):
1660+
def can_delete_datasets(team_uuid, dataset_uuid_requested_list):
16611661
can_delete_datasets = True
16621662
messages = []
1663-
dataset_uuid_requested_list = json.loads(dataset_uuids_json)
16641663
all_dataset_entities = retrieve_dataset_list(team_uuid)
16651664
# Build a list of the dataset uuids that we found.
16661665
dataset_uuids_found_list = []
@@ -1704,10 +1703,9 @@ def can_delete_datasets(team_uuid, dataset_uuids_json):
17041703
messages.append(message)
17051704
return can_delete_datasets, messages
17061705

1707-
def can_delete_models(team_uuid, model_uuids_json):
1706+
def can_delete_models(team_uuid, model_uuid_requested_list):
17081707
can_delete_models = True
17091708
messages = []
1710-
model_uuid_requested_list = json.loads(model_uuids_json)
17111709
all_model_entities = retrieve_model_list(team_uuid)
17121710
# Build a list of the model uuids that we found.
17131711
model_uuids_found_list = []

0 commit comments

Comments
 (0)