Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

タスク作成処理をinitiateTasksGenerationAPIからputTaskAPIを使うように変更しました。 #98

Merged
merged 2 commits into from
Jul 28, 2022

Conversation

yuji38kwmt
Copy link
Collaborator

@yuji38kwmt yuji38kwmt commented Jul 16, 2022

タスク作成の処理をinitiateTasksGenerationAPIからputTaskAPIを使うように変更しました。
理由は以下の通りです。

  • タスク作成処理が少ない(おおよそ200件以下)場合は、putTask APIの方が速い
  • initiateTasksGeneration APIでは、タスク作成に失敗した際のエラーが分かりづらい

Comment on lines -33 to -50
def create_tasks_by_csv(self, csv_path: Path) -> TaskGenerateResponse:
client = self._client
project_id = self._project_id
uploader = AnnofabStorageUploader(client, project_id)
project = self._project.get_project(project_id)
if project is None:
raise RuntimeError("指定されたプロジェクト(={})が見つかりませんでした。".format(project_id))

uploaded_path = uploader.upload_tempdata(csv_path)

body_params = {
"task_generate_rule": {"csv_data_path": uploaded_path, "_type": "ByInputDataCsv"},
"project_last_updated_datetime": project.updated_datetime,
}
task_generate_result, _ = client.initiate_tasks_generation(project_id, request_body=body_params)

return TaskGenerateResponse.from_dict(task_generate_result)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使わなくなったので削除

def put_task(self, task_id: str, input_data_ids: List[str]) -> Task:
client = self._client
project_id = self._project_id
result, _ = client.put_task(project_id, task_id, request_body={"input_data_id_list": input_data_ids})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既にタスクが存在していたら、HTTPErrorが発生する。

タスクを上書きするとアノテーションが消える可能性があり、入力データや補助情報データの上書きよりも、慎重に行う必要があるため、--forceが指定されても、タスクは上書きしないようにした。


logger.info("タスクの作成が完了しました")
logger.info("タスクの作成を開始します")
await asyncio.gather(self._create_tasks_async(uploader_input.project_id, task_to_data_dict))

This comment was marked as resolved.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解決済

@yuji38kwmt yuji38kwmt changed the title タスク作成処理の変更 タスク作成処理woinitiateTasksGenerationAPIからputTaskAPI Jul 18, 2022
@yuji38kwmt yuji38kwmt changed the title タスク作成処理woinitiateTasksGenerationAPIからputTaskAPI タスク作成処理をinitiateTasksGenerationAPIからputTaskAPIを使うように変更しました。 Jul 18, 2022
@@ -57,6 +37,12 @@ def get_task(self, task_id: str) -> Optional[Task]:

return self._decode_task(result)

def put_task(self, task_id: str, input_data_ids: Collection[str]) -> Task:
Copy link
Collaborator Author

@yuji38kwmt yuji38kwmt Jul 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input_daata_idsの型がListでなくCollectionにした理由は、mypyに怒られないようにするため。

poetry run mypy anno3d tests sandbox.py
anno3d/kitti/scene_uploader.py:152: error: Argument 2 to "put_task" of "TaskApi" has incompatible type "List[DataId]"; expected "List[str]"
anno3d/kitti/scene_uploader.py:152: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
anno3d/kitti/scene_uploader.py:152: note: Consider using "Sequence" instead, which is covariant

@yuji38kwmt yuji38kwmt marked this pull request as ready for review July 19, 2022 09:21
@yuji38kwmt yuji38kwmt force-pushed the modify-upload-task branch 3 times, most recently from a8b99be to e0c1133 Compare July 28, 2022 01:30
Copy link
Contributor

@seraphr seraphr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

動作確認した

loop = asyncio.get_event_loop()
project = self._project
task = TaskApi(self._client, project, project_id)
def _create_tasks(self, project_id: str, task_to_data_dict: Dict[TaskId, List[Tuple[DataId, FilePaths]]]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

返り値の型を明示してほしいです

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#102 で対応しました。

@seraphr seraphr merged commit 5f4b88e into master Jul 28, 2022
@seraphr seraphr deleted the modify-upload-task branch July 28, 2022 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants