2727 UNIVERSE_URL ,
2828)
2929from roboflow .core .dataset import Dataset
30- from roboflow .models .classification import ClassificationModel
31- from roboflow .models .instance_segmentation import InstanceSegmentationModel
32- from roboflow .models .keypoint_detection import KeypointDetectionModel
33- from roboflow .models .object_detection import ObjectDetectionModel
34- from roboflow .models .semantic_segmentation import SemanticSegmentationModel
35- from roboflow .models .vlm import VLMModel
3630from roboflow .util .annotations import amend_data_yaml
3731from roboflow .util .general import extract_zip , write_line
38- from roboflow .util .model_processor import package_custom_weights_interactive , validate_model_type_for_project
3932from roboflow .util .train_recipe import fold_epochs_into_recipe
40- from roboflow .util .versions import get_model_format , get_wrong_dependencies_versions
4133
4234if TYPE_CHECKING :
4335 import numpy as np
@@ -103,6 +95,8 @@ def __init__(
10395 if not has_model :
10496 self .model = None
10597 elif self .type == TYPE_OBJECT_DETECTION :
98+ from roboflow .models .object_detection import ObjectDetectionModel
99+
106100 self .model = ObjectDetectionModel (
107101 self .__api_key ,
108102 self .id ,
@@ -113,6 +107,8 @@ def __init__(
113107 preprocessing = self .preprocessing ,
114108 )
115109 elif self .type == TYPE_CLASSICATION :
110+ from roboflow .models .classification import ClassificationModel
111+
116112 self .model = ClassificationModel (
117113 self .__api_key ,
118114 self .id ,
@@ -123,6 +119,8 @@ def __init__(
123119 preprocessing = self .preprocessing ,
124120 )
125121 elif self .type == TYPE_INSTANCE_SEGMENTATION :
122+ from roboflow .models .instance_segmentation import InstanceSegmentationModel
123+
126124 self .model = InstanceSegmentationModel (
127125 self .__api_key ,
128126 self .id ,
@@ -131,10 +129,16 @@ def __init__(
131129 local = local ,
132130 )
133131 elif self .type == TYPE_SEMANTIC_SEGMENTATION :
132+ from roboflow .models .semantic_segmentation import SemanticSegmentationModel
133+
134134 self .model = SemanticSegmentationModel (self .__api_key , self .id )
135135 elif self .type == TYPE_KEYPOINT_DETECTION :
136+ from roboflow .models .keypoint_detection import KeypointDetectionModel
137+
136138 self .model = KeypointDetectionModel (self .__api_key , self .id , version = version_without_workspace )
137139 elif self .type == TYPE_TEXT_IMAGE_PAIRS :
140+ from roboflow .models .vlm import VLMModel
141+
138142 self .model = VLMModel (
139143 self .__api_key ,
140144 self .id ,
@@ -300,6 +304,8 @@ def create_training(self, speed=None, model_type=None, checkpoint=None, epochs=N
300304 self .__wait_if_generating ()
301305
302306 if model_type :
307+ from roboflow .util .versions import get_model_format
308+
303309 train_model_format = get_model_format (model_type )
304310 if train_model_format not in self .exports :
305311 self .export (train_model_format )
@@ -486,6 +492,8 @@ def train(
486492
487493 self .__wait_if_generating ()
488494
495+ from roboflow .util .versions import get_model_format
496+
489497 train_model_format = get_model_format (model_type )
490498 if train_model_format not in self .exports :
491499 self .export (train_model_format )
@@ -609,6 +617,8 @@ def live_plot(epochs, mAP, loss, title=""):
609617
610618 if not getattr (self , "_model" , None ):
611619 if self .type == TYPE_OBJECT_DETECTION :
620+ from roboflow .models .object_detection import ObjectDetectionModel
621+
612622 self .model = ObjectDetectionModel (
613623 self .__api_key ,
614624 self .id ,
@@ -618,6 +628,8 @@ def live_plot(epochs, mAP, loss, title=""):
618628 preprocessing = self .preprocessing ,
619629 )
620630 elif self .type == TYPE_CLASSICATION :
631+ from roboflow .models .classification import ClassificationModel
632+
621633 self .model = ClassificationModel (
622634 self .__api_key ,
623635 self .id ,
@@ -627,15 +639,21 @@ def live_plot(epochs, mAP, loss, title=""):
627639 preprocessing = self .preprocessing ,
628640 )
629641 elif self .type == TYPE_INSTANCE_SEGMENTATION :
642+ from roboflow .models .instance_segmentation import InstanceSegmentationModel
643+
630644 self .model = InstanceSegmentationModel (
631645 self .__api_key ,
632646 self .id ,
633647 colors = self .colors ,
634648 preprocessing = self .preprocessing ,
635649 )
636650 elif self .type == TYPE_SEMANTIC_SEGMENTATION :
651+ from roboflow .models .semantic_segmentation import SemanticSegmentationModel
652+
637653 self .model = SemanticSegmentationModel (self .__api_key , self .id )
638654 elif self .type == TYPE_KEYPOINT_DETECTION :
655+ from roboflow .models .keypoint_detection import KeypointDetectionModel
656+
639657 self .model = KeypointDetectionModel (self .__api_key , self .id , version = self .version )
640658 else :
641659 raise ValueError (f"Unsupported model type: { self .type } " )
@@ -653,12 +671,16 @@ def deploy(self, model_type: str, model_path: str, filename: str = "weights/best
653671 model_path (str): File path to the model weights to be uploaded.
654672 filename (str, optional): The name of the weights file. Defaults to "weights/best.pt".
655673 """
674+ from roboflow .util .model_processor import package_custom_weights_interactive
675+
656676 bundle = package_custom_weights_interactive (model_type , model_path , filename , build_dir = model_path )
657677
658678 self ._validate_against_project_type (bundle .model_type )
659679 self ._upload_zip (bundle .model_type , model_path , bundle .archive_path .name )
660680
661681 def _validate_against_project_type (self , model_type : str ) -> None :
682+ from roboflow .util .model_processor import validate_model_type_for_project
683+
662684 validate_model_type_for_project (model_type , self .type , self .project )
663685
664686 def _upload_zip (self , model_type : str , model_path : str , model_file_name : str ):
@@ -818,6 +840,8 @@ def data_yaml_callback(content: dict) -> dict:
818840 content ["train" ] = location + content ["train" ].lstrip (".." )
819841 content ["val" ] = location + content ["val" ].lstrip (".." )
820842 try :
843+ from roboflow .util .versions import get_wrong_dependencies_versions
844+
821845 # get_wrong_dependencies_versions raises exception if ultralytics is not installed at all # noqa: E501 // docs
822846 if format == "yolov8" and not get_wrong_dependencies_versions (
823847 dependencies_versions = [("ultralytics" , "==" , "8.0.196" )]
0 commit comments