From 0a821118dd6d979ffbaf534cd8351466675e5c4b Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Thu, 30 May 2024 20:30:41 +0545 Subject: [PATCH 1/2] Move import dependencies --- backend/core/tasks.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/core/tasks.py b/backend/core/tasks.py index bfbf7c3b..f8c4f87b 100644 --- a/backend/core/tasks.py +++ b/backend/core/tasks.py @@ -7,9 +7,7 @@ import traceback from shutil import rmtree -import hot_fair_utilities -import ramp.utils -import tensorflow as tf + from celery import shared_task from core.models import AOI, Feedback, FeedbackAOI, FeedbackLabel, Label, Training from core.serializers import ( @@ -25,8 +23,6 @@ from django.contrib.gis.geos import GEOSGeometry from django.shortcuts import get_object_or_404 from django.utils import timezone -from hot_fair_utilities import preprocess, train -from hot_fair_utilities.training import run_feedback from predictor import download_imagery, get_start_end_download_coords logger = logging.getLogger(__name__) @@ -82,6 +78,13 @@ def train_model( feedback=None, freeze_layers=False, ): + #importing them here so that it won't be necessary when sending tasks + import hot_fair_utilities + import ramp.utils + import tensorflow as tf + from hot_fair_utilities import preprocess, train + from hot_fair_utilities.training import run_feedback + training_instance = get_object_or_404(Training, id=training_id) training_instance.status = "RUNNING" training_instance.started_at = timezone.now() From 9e8c553c32cd252a0edac2abc8dd70382f608f50 Mon Sep 17 00:00:00 2001 From: kshitijrajsharma Date: Thu, 30 May 2024 21:29:32 +0545 Subject: [PATCH 2/2] fix(tasks): only import lib when function is executed fixes the bug about not being able to run api only using api-requirements --- backend/core/tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/core/tasks.py b/backend/core/tasks.py index f8c4f87b..b037ab01 100644 --- a/backend/core/tasks.py +++ b/backend/core/tasks.py @@ -78,7 +78,7 @@ def train_model( feedback=None, freeze_layers=False, ): - #importing them here so that it won't be necessary when sending tasks + #importing them here so that it won't be necessary when sending tasks ( api only) import hot_fair_utilities import ramp.utils import tensorflow as tf