FocoosHUB
Focoos Module
This module provides a Python interface for interacting with Focoos APIs, allowing users to manage machine learning models and datasets in the Focoos ecosystem. The module supports operations such as retrieving model metadata, downloading models, and listing shared datasets.
Classes:
Name | Description |
---|---|
FocoosHUB |
Main class to interface with Focoos APIs. |
Raises:
Type | Description |
---|---|
ValueError
|
Raised for invalid API responses or missing parameters. |
FocoosHUB
#
Main class to interface with Focoos APIs.
This class provides methods to interact with Focoos-hosted models and datasets. It supports functionalities such as listing models, retrieving model metadata, downloading models, and creating new models.
Attributes:
Name | Type | Description |
---|---|---|
api_key |
str
|
The API key for authentication. |
api_client |
ApiClient
|
HTTP client for making API requests. |
user_info |
User
|
Information about the currently authenticated user. |
host_url |
str
|
Base URL for the Focoos API. |
Source code in focoos/hub/focoos_hub.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|
__init__(api_key=None, host_url=None)
#
Initializes the FocoosHUB client.
This client provides authenticated access to the Focoos API, enabling various operations through the configured HTTP client. It retrieves user information upon initialization and logs the environment details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
api_key
|
Optional[str]
|
API key for authentication. Defaults to the |
None
|
host_url
|
Optional[str]
|
Base URL for the Focoos API. Defaults to the |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
If the API key is not provided, or if the host URL is not specified in the arguments or the configuration. |
Attributes:
Name | Type | Description |
---|---|---|
api_key |
str
|
The API key used for authentication. |
api_client |
ApiClient
|
An HTTP client instance configured with the API key and host URL. |
user_info |
User
|
Information about the authenticated user retrieved from the API. |
host_url |
str
|
The base URL used for API requests. |
Logs
- Error if the API key or host URL is missing.
- Info about the authenticated user and environment upon successful initialization.
Example
1 2 3 |
|
Source code in focoos/hub/focoos_hub.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
download_model_pth(model_ref, skip_if_exists=True)
#
Downloads a model from the Focoos API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_ref
|
str
|
Reference identifier for the model. |
required |
skip_if_exists
|
bool
|
If True, skips the download if the model file already exists. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path to the downloaded model file. |
Raises:
Type | Description |
---|---|
ValueError
|
If the API request fails or the download fails. |
Source code in focoos/hub/focoos_hub.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
get_model_info(model_ref)
#
Retrieves metadata for a specific model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_ref
|
str
|
Reference identifier for the model. |
required |
Returns:
Name | Type | Description |
---|---|---|
RemoteModelInfo |
RemoteModelInfo
|
Metadata of the specified model. |
Raises:
Type | Description |
---|---|
ValueError
|
If the API request fails. |
Example
1 2 3 4 |
|
Source code in focoos/hub/focoos_hub.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
get_remote_dataset(ref)
#
Retrieves a remote dataset by its reference ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref
|
str
|
The reference ID of the dataset to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
RemoteDataset |
RemoteDataset
|
A RemoteDataset instance for the specified reference. |
Example
1 2 3 4 |
|
Source code in focoos/hub/focoos_hub.py
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
get_remote_model(model_ref)
#
Retrieves a remote model instance for cloud-based inference.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_ref
|
str
|
Reference identifier for the model. |
required |
Returns:
Name | Type | Description |
---|---|---|
RemoteModel |
RemoteModel
|
The remote model instance configured for cloud-based inference. |
Example
1 2 3 4 5 |
|
Source code in focoos/hub/focoos_hub.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
get_user_info()
#
Retrieves information about the authenticated user.
Returns:
Name | Type | Description |
---|---|---|
User |
User
|
User object containing account information and usage quotas. |
Raises:
Type | Description |
---|---|
ValueError
|
If the API request fails. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Source code in focoos/hub/focoos_hub.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
list_remote_datasets(include_shared=False)
#
Lists all datasets available to the user.
This method retrieves all datasets owned by the user and optionally includes shared datasets as well.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include_shared
|
bool
|
If True, includes datasets shared with the user. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
list[DatasetPreview]
|
list[DatasetPreview]: A list of DatasetPreview objects representing the available datasets. |
Raises:
Type | Description |
---|---|
ValueError
|
If the API request to list datasets fails. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Source code in focoos/hub/focoos_hub.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
list_remote_models()
#
Lists all models owned by the user.
Returns:
Type | Description |
---|---|
list[ModelPreview]
|
list[ModelPreview]: List of model previews. |
Raises:
Type | Description |
---|---|
ValueError
|
If the API request fails. |
Example
1 2 3 4 |
|
Source code in focoos/hub/focoos_hub.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
new_model(model_info)
#
Creates a new model in the Focoos platform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the new model. |
required |
focoos_model
|
str
|
Reference to the base Focoos model. |
required |
description
|
str
|
Description of the new model. |
required |
Returns:
Type | Description |
---|---|
Optional[RemoteModel]
|
Optional[RemoteModel]: The created model instance, or None if creation fails. |
Raises:
Type | Description |
---|---|
ValueError
|
If the API request fails. |
Example
1 2 3 4 |
|
Source code in focoos/hub/focoos_hub.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|
RemoteDataset
#
A class to manage remote datasets through the Focoos API.
This class provides functionality to interact with datasets stored remotely, including uploading, downloading, and managing dataset data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref
|
str
|
The reference identifier for the dataset. |
required |
api_client
|
ApiClient
|
The API client instance for making requests. |
required |
Attributes:
Name | Type | Description |
---|---|---|
ref |
str
|
The dataset reference identifier. |
api_client |
ApiClient
|
The API client instance. |
metadata |
DatasetPreview
|
The dataset metadata. |
Source code in focoos/hub/remote_dataset.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
download_data(path=DATASETS_DIR)
#
Downloads the dataset data to a local path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Local path where the dataset should be downloaded. |
DATASETS_DIR
|
Returns:
Name | Type | Description |
---|---|---|
str |
The path where the file was downloaded. |
Raises:
Type | Description |
---|---|
ValueError
|
If the download fails. |
Source code in focoos/hub/remote_dataset.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
get_info()
#
Retrieves the dataset information from the API.
Returns:
Name | Type | Description |
---|---|---|
DatasetPreview |
DatasetPreview
|
The dataset preview information. |
Source code in focoos/hub/remote_dataset.py
33 34 35 36 37 38 39 40 41 42 43 |
|
upload_data(path)
#
Uploads dataset data from a local zip file to the remote storage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Local path to the zip file containing dataset data. |
required |
Returns:
Type | Description |
---|---|
Optional[DatasetSpec]
|
Optional[DatasetSpec]: The dataset specification after successful upload. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the specified file does not exist. |
ValueError
|
If the file is not a zip file or upload fails. |
Source code in focoos/hub/remote_dataset.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
RemoteModel Module
This module provides a class to manage remote models in the Focoos ecosystem. It supports various functionalities including model training, deployment, inference, and monitoring.
Classes:
Name | Description |
---|---|
RemoteModel |
A class for interacting with remote models, managing their lifecycle, and performing inference. |
Functions:
Name | Description |
---|---|
__init__ |
Initializes the RemoteModel instance. |
get_info |
Retrieves model metadata. |
train |
Initiates model training. |
train_info |
Retrieves training status. |
train_logs |
Retrieves training logs. |
metrics |
Retrieves model metrics. |
RemoteModel
#
Represents a remote model in the Focoos platform.
Attributes:
Name | Type | Description |
---|---|---|
model_ref |
str
|
Reference ID for the model. |
api_client |
ApiClient
|
Client for making HTTP requests. |
model_info |
RemoteModelInfo
|
Model information of the model. |
Source code in focoos/hub/remote_model.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
__init__(model_ref, api_client)
#
Initialize the RemoteModel instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_ref
|
str
|
Reference ID for the model. |
required |
api_client
|
ApiClient
|
HTTP client instance for communication. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If model metadata retrieval fails. |
Source code in focoos/hub/remote_model.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
get_info()
#
Retrieve model metadata.
Returns:
Name | Type | Description |
---|---|---|
ModelMetadata |
RemoteModelInfo
|
Metadata of the model. |
Raises:
Type | Description |
---|---|
ValueError
|
If the request fails. |
Example
1 2 3 4 5 |
|
Source code in focoos/hub/remote_model.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
infer(image, threshold=0.5, annotate=False)
#
Run inference on an image using the remote model and return detection results.
This method uploads an image to the remote model for inference. The image can be provided as a file path, a string path, a NumPy array, raw bytes, or a PIL Image. The method returns detection results, including class IDs, confidence scores, bounding boxes, and segmentation masks if available. Optionally, the results can be returned with the image annotated with detections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
Union[str, Path, ndarray, bytes, Image]
|
The image to run inference on. |
required |
threshold
|
float
|
Minimum confidence threshold for detections. Detections below this threshold are filtered out. Default is 0.5. |
0.5
|
annotate
|
bool
|
If True, returns the image with detections drawn on it. Default is False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
FocoosDetections |
FocoosDetections
|
Detection results, including a list of detections and optional annotated image. |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the image file path does not exist or cannot be loaded. |
ValueError
|
If the inference request to the remote model fails. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Source code in focoos/hub/remote_model.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
metrics()
#
Retrieve the metrics of the model.
This method sends a request to fetch the metrics of the model identified by model_ref
.
If the request is successful (status code 200), it returns the metrics as a Metrics
object.
If the request fails, it logs a warning and returns an empty Metrics
object.
Returns:
Name | Type | Description |
---|---|---|
Metrics |
Metrics
|
An object containing the metrics of the model. |
Raises:
Type | Description |
---|---|
None
|
Returns an empty |
Source code in focoos/hub/remote_model.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
notebook_monitor_train(interval=30, plot_metrics=False, max_runtime=36000)
#
Monitor the training process in a Jupyter notebook and display metrics.
Periodically checks the training status and displays metrics in a notebook cell. Clears previous output to maintain a clean view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
interval
|
int
|
Time between status checks in seconds. Must be 30-240. Default: 30 |
30
|
plot_metrics
|
bool
|
Whether to plot metrics graphs. Default: False |
False
|
max_runtime
|
int
|
Maximum monitoring time in seconds. Default: 36000 (10 hours) |
36000
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in focoos/hub/remote_model.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
train_info()
#
Retrieve the current status of the model training.
Sends a request to check the training status of the model referenced by self.model_ref
.
Returns:
Name | Type | Description |
---|---|---|
dict |
Optional[TrainingInfo]
|
A dictionary containing the training status information. |
Raises:
Type | Description |
---|---|
ValueError
|
If the request to get training status fails. |
Source code in focoos/hub/remote_model.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
train_logs()
#
Retrieve the training logs for the model.
This method sends a request to fetch the logs of the model's training process. If the request is successful (status code 200), it returns the logs as a list of strings. If the request fails, it logs a warning and returns an empty list.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: A list of training logs as strings. |
Raises:
Type | Description |
---|---|
None
|
Returns an empty list if the request fails. |
Source code in focoos/hub/remote_model.py
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
|