api Package
models Module
Django models module for the ‘api’ application.
This module defines Django models representing data entities related to user projects and machine learning models.
from django.db import models from django.contrib.auth.models import User
- class api.models.LearningModel(*args, **kwargs)
Django model representing a machine learning model.
- Attributes:
name (CharField): The name of the model. architecture (CharField): The architecture of the model. learning_rate (FloatField): The learning rate used in training the model. weight_decay (FloatField): The weight decay used in training the model. epochs (PositiveIntegerField): The number of training epochs. validation_set_size (IntegerField): The size of the validation set. miou_score (FloatField): The Mean IoU score achieved by the model. top1_score (FloatField): The top-1 accuracy score achieved by the model. top5_score (FloatField): The top-5 accuracy score achieved by the model. checkpoint (BinaryField): The binary representation of the model’s checkpoint. project (ForeignKey): The project associated with the model.
- Methods:
model_id(): Returns the unique identifier of the model.
- Meta:
db_table (str): The name of the database table for the ‘LearningModel’ model.
- class Architecture(value)
Enumeration of supported model architectures.
- exception DoesNotExist
- exception MultipleObjectsReturned
- property model_id
Get the unique identifier of the model.
- Returns:
int: The unique identifier of the model.
- class api.models.Project(*args, **kwargs)
Django model representing a user’s project.
- Attributes:
title (CharField): The title of the project. description (CharField): The description of the project. label_studio_project (CharField): The ID of the associated label studio project. user (ForeignKey): The user associated with the project.
- Methods:
project_id(): Returns the unique identifier of the project.
- Meta:
db_table (str): The name of the database table for the ‘Project’ model.
- exception DoesNotExist
- exception MultipleObjectsReturned
- property project_id
Get the unique identifier of the project.
- Returns:
int: The unique identifier of the project.
views Module
Django Views for API Endpoints.
This module contains Django views that handle various API endpoints for user authentication, project and learning model management, file uploads, making predictions, and training models.
- class api.views.ListModelsView(**kwargs)
Handles listing and creating learning models for authenticated users.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
get(request, *args, **kwargs): Handles HTTP GET for listing models for a specific project.
- get(request, *args, **kwargs)
Handle HTTP GET for listing models for a specific project.
Returns a JSON response containing the learning models associated with the specified project.
- class api.views.ListProjectsView(**kwargs)
Handles listing and creating projects for authenticated users.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
get(request, format=None): Handles HTTP GET for listing the user’s projects.
- get(request, format=None)
Handle HTTP GET for listing the user’s projects.
Returns a JSON response containing the projects associated with the authenticated user.
- Args:
request (Request): HTTP request object. format (str, optional): Requested format. Defaults to None.
- Returns:
JsonResponse: JSON response containing user’s projects.
- class api.views.ListScoresView(**kwargs)
Handles listing scores for authenticated users.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
get(request, *args, **kwargs): Handles HTTP GET for listing scores of a learning model.
- get(request, *args, **kwargs)
Handle HTTP GET for listing scores of a learning model.
Returns a JSON response containing scores for the specified learning model.
- class api.views.LoginView(**kwargs)
Handles user login and generates an authentication token upon successful login.
- Attributes:
serializer_class (Serializer): Serializer for user login data (RequestSerializer).
- Methods:
post(request, format=None): Handles HTTP POST for user login.
- post(request, format=None)
Handle HTTP POST for user login.
Validates user credentials, generates an authentication token, and returns the token and user data upon successful login.
- Args:
request (Request): HTTP request object. format (str, optional): Requested format. Defaults to None.
- Returns:
- Response: HTTP response containing the authentication token and user data
upon successful login or error details if login fails.
- serializer_class
alias of
RequestSerializer
- class api.views.LogoutView(**kwargs)
Handles user logout by deleting the authentication token.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
get(request, format=None): Handles HTTP GET for logging out a user.
- get(request, format=None)
Handle HTTP GET for logging out a user.
Deletes the authentication token for the authenticated user.
- Args:
request (Request): HTTP request object. format (str, optional): Requested format. Defaults to None.
- Returns:
Response: HTTP response indicating success or failure of logout.
- class api.views.MakePredictionsView(**kwargs)
Handles making predictions for authenticated users.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
validate(project_id, model_id): Validates the learning model for the given project. get(request, *args, **kwargs): Handles HTTP GET for making predictions.
- get(request, *args, **kwargs)
Handle HTTP GET for making predictions.
Makes predictions using the specified learning model and project.
- validate(project_id, model_id)
Validate the learning model for the given project.
- Args:
project_id (str): ID of the project. model_id (str): ID of the learning model.
- Returns:
bool: True if the learning model is valid, False otherwise.
- class api.views.ModelCreateView(**kwargs)
Handles creating a new learning model for authenticated users.
- class api.views.ProjectCreateView(**kwargs)
Handles creating projects for authenticated users.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
post(request, *args, **kwargs): Handles HTTP POST for creating a new project.
- post(request, *args, **kwargs)
Handle HTTP POST for creating a new project.
Creates a new project associated with the authenticated user.
- class api.views.ProjectDeleteView(**kwargs)
Handles deleting projects for authenticated users.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
post(request, *args, **kwargs): Handles HTTP POST for deleting a project.
- post(request, *args, **kwargs)
Handle HTTP POST for deleting a project.
Deletes the project with the specified ID associated with the authenticated user.
- class api.views.ProjectEditView(**kwargs)
Handles editing projects for authenticated users.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
post(request, *args, **kwargs): Handles HTTP POST for editing a project.
- post(request, *args, **kwargs)
Handle HTTP POST for editing a project.
Edits the project with the specified ID associated with the authenticated user.
- class api.views.SignUpView(**kwargs)
Handles user registration and creates an authentication token upon successful signup.
- Attributes:
serializer_class (Serializer): Serializer for user registration data (RequestSerializer).
- Methods:
post(request, format=None): Handles HTTP POST for user registration.
- post(request, format=None)
Handle HTTP POST for user registration.
Creates a new user, sets the user’s password, generates an authentication token, and returns the token and user data upon successful registration.
- Args:
request (Request): HTTP request object. format (str, optional): Requested format. Defaults to None.
- Returns:
- Response: HTTP response containing the authentication token and user data
upon successful registration or error details if registration fails.
- serializer_class
alias of
RequestSerializer
- class api.views.TestTokenView(**kwargs)
Handles testing the validity of the authentication token.
- Attributes:
authentication_classes (list): List of authentication classes (SessionAuthentication, TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
get(request, format=None): Handles HTTP GET for testing the validity of the authentication token.
- get(request, format=None)
Handle HTTP GET for testing the validity of the authentication token.
- Args:
request (Request): HTTP request object. format (str, optional): Requested format. Defaults to None.
- Returns:
Response: HTTP response indicating the success of the authentication token test.
- class api.views.TrainView(**kwargs)
Handles triggering the training process for a machine learning model.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
post(request, *args, **kwargs): Handles HTTP POST for triggering the training process for a machine learning model.
- post(request, *args, **kwargs)
Handle HTTP POST for triggering the training process for a machine learning model.
- class api.views.UploadAnnotationView(**kwargs)
Handles uploading annotations file for a machine learning model.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated). parser_classes (list): List of parser classes (MultiPartParser, FormParser).
- Methods:
dispatch(*args, **kwargs): Overrides the default dispatch method to ensure proper handling.
post(request, *args, **kwargs): Handles HTTP POST for uploading annotations file for a machine learning model.
- dispatch(*args, **kwargs)
Overrides the default dispatch method to ensure proper handling.
- post(request, *args, **kwargs)
Handles HTTP POST for uploading annotations file for a machine learning model.
- class api.views.UploadFilesView(**kwargs)
Handles uploading dataset files for a project.
- Attributes:
authentication_classes (list): List of authentication classes (TokenAuthentication). permission_classes (list): List of permission classes (IsAuthenticated).
- Methods:
post(request, *args, **kwargs): Handles HTTP POST for uploading files for a project.
- post(request, *args, **kwargs)
Handle HTTP POST for uploading dataset files for a project.
serializers Module
Django REST framework serializers module for the ‘api’ application.
This module defines serializers for converting complex data types, such as Django models, into Python data types that can be easily rendered into JSON and other content types.
- class api.serializers.CreateModelSerializer(*args, **kwargs)
Serializer for creating a new learning model.
- Meta:
model (LearningModel): The model to be serialized. exclude (tuple): The fields to exclude from the serialization.
- class api.serializers.ListModelSerializer(*args, **kwargs)
Serializer for listing learning models with selected attributes.
- Meta:
model (LearningModel): The model to be serialized. fields (tuple): The fields to include in the serialization.
- class api.serializers.ListScoresSerializer(*args, **kwargs)
Serializer for listing scores of a learning model.
- Meta:
model (LearningModel): The model to be serialized. fields (tuple): The fields to include in the serialization.
- class api.serializers.ProjectSerializer(*args, **kwargs)
Serializer for the ‘Project’ model.
- Meta:
model (Project): The model to be serialized. fields (list): The fields to include in the serialization.
- class api.serializers.RequestSerializer(*args, **kwargs)
Serializer for user registration and login data.
- Meta:
model (AuthenticationUser): The model to be serialized. fields (list): The fields to include in the serialization.