svnm - A Simplified Deep Learning Models Package
svnm is a Python package designed to simplify the process of using deep learning models in your code. With just a simple import, you can easily load pre-trained models and make predictions with minimal setup. This package is aimed at making deep learning models more accessible for developers, enabling rapid experimentation and deployment.
Routing
Image Classification
Features
- Easy-to-use interface: Import the package and start making predictions with minimal code.
- Pre-trained models: Includes popular deep learning models ready for use without additional training.
- Flexible prediction methods: Support for various types of input data to make predictions.
- Lightweight and efficient: Focuses on simplifying deep learning workflows without overhead.
Installation
To install svnm, simply use pip:
pip install svnm
Model Usage
Gender Detection
from svnm.models import GenderDetection
model = GenderDetection()
# Single Prediction
prediction, confidence = model.predict("face_image.jpg")
print(f"Predicted Gender: {prediction} with confidence {confidence:.2f}")
# Batch Prediction
image_paths = ["face1.jpg", "face2.jpg", "face3.jpg"]
predictions = model.predict_batch(image_paths)
for img, (label, conf) in zip(image_paths, predictions):
print(f"Image: {img} -> Predicted Gender: {label} with confidence {conf:.2f}")
# Visualization
model.visualize_prediction("face_image.jpg")
How Gender Detection Works
The Gender Detection model in svnm classifies whether a detected face belongs to a male or female. It works as follows:
- Loading the Model: The pre-trained deep learning model is loaded automatically when the
GenderDetectionclass is initialized. - Processing the Image: The input image is preprocessed and resized before being fed into the model.
- Making Predictions: The model analyzes the facial features and predicts the gender along with a confidence score.
- Batch Processing:
- Supports batch predictions for multiple images at once.
- Each image is processed individually, and the results are returned as a list.
- Visualization:
- If
visualize_prediction()is called, the image is displayed with the predicted gender and confidence score.
- If
Face Detection
from svnm.models import FaceDetection
model = FaceDetection(save=True, save_dir="predictions")
# Single Image Prediction
predictions = model.predict("face_image.jpg")
print("Face Detection Results:", predictions)
# Batch Prediction
image_paths = ["face1.jpg", "face2.jpg", "face3.jpg"]
batch_predictions = model.predict_batch(image_paths)
for img, preds in zip(image_paths, batch_predictions):
print(f"Image: {img} -> Predictions: {preds}")
How Face Detection Works
The Face Detection model in svnm is designed to detect human faces in images. It works as follows:
- Loading the Model: The pre-trained YOLO-based face detection model is loaded automatically when the
FaceDetectionclass is initialized. - Processing the Image: The input image is read, preprocessed, and fed into the model.
- Detecting Faces: The model detects faces in the image and returns bounding box coordinates, confidence scores, and class labels.
- Batch Processing:
- Supports batch predictions for multiple images at once.
- Each image is processed individually, and the results are returned as a list.
- Saving and Visualizing Results:
- If
save=True, the detected faces are highlighted in the image and saved to the specified directory. - The model outputs a list of detected faces with their positions and confidence levels.
- If
FaceRecognition Class
FaceRecognition(models=None)
- Description: Initialize the class with a list of DeepFace models. Default models are:
["Facenet", "OpenFace"]. - Parameters:
models(optional): List of model names to use.
detect_face(image_path, show=True)
- Description: Detects faces in an image using OpenCV Haar Cascade.
- Parameters:
image_path: Path to the image.show: IfTrue, displays the detected face(s).
- Returns: Tuple
(faces, image_with_rectangles)
get_combined_embedding(image_path)
- Description: Extracts embeddings from selected models and calculates:
- Average embedding
- Concatenated embedding
- Standard deviation embedding
- Returns:
{ "avg": np.array, "concat": np.array, "std": np.array }
compare_embeddings(embedding1, embedding2)
- Description: Compares two embeddings using cosine similarity.
- Parameters:
embedding1: Output ofget_combined_embeddingembedding2: Output ofget_combined_embedding
- Returns: Dictionary of similarity scores for each method:
"avg","concat", and"std"
train(df, save=False, json_path="trained_data.json")
- Description: Trains the recognizer with a DataFrame of image paths and labels.
- Parameters:
df: Pandas DataFrame withpathandlabelcolumns.save: IfTrue, saves the result to a JSON file.json_path: Path to output JSON file.
find_best_match(image, source_type=None)
- Description: Finds the best matching label for a new image using cosine similarity on
concatembeddings. - Parameters:
image: Image path or URLsource_type:'url'or'path'. Defaults to'path'
- Returns: Tuple:
(predicted_label, similarity_score)
Handwritten Digit Recognition
from svnm.models import HandwrittenDigitRecognition
model = HandwrittenDigitRecognition()
# Single Image Prediction
prediction = model.predict("digit_image.jpg")
print("Predicted Digit:", prediction)
How Handwritten Digit Recognition Works
- Loading the Model: The pre-trained digit recognition model is initialized.
- Processing the Image: The input image is resized and normalized before being fed into the model.
- Making Predictions:
- The model predicts the digit and outputs the confidence score.
- Supports batch predictions for multiple images at once.
Example Output
{"digit": 7, "confidence": 0.98}
Metadata
Release files for svnm 1.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| svnm-1.4.2.tar.gz | 12.8 kB | Without provenance | Details for svnm-1.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| svnm-1.4.2-py3-none-any.whl | Python 3 | none | any | Details for svnm-1.4.2-py3-none-any.whl |
Total release size: 26.5 kB
Release files / svnm-1.4.2.tar.gz
| Download URL | svnm-1.4.2.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88d5485136157147bc302570f2a90b0f76bdc6d84d3ed9baf508699d7eca6cf7
|
|
BLAKE2b-256 checksum How to use checksums |
0f39263a97aa80e8b3d82af3c803e23c6b845a23c1069e7f16426c1a9123ae4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.1
|
Release files / svnm-1.4.2-py3-none-any.whl
| Download URL | svnm-1.4.2-py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23b646617eedd069cca2632fd09af85592b0d42fbf86d497819cf5134044476d
|
|
BLAKE2b-256 checksum How to use checksums |
07901a4d4fede9d2f72ecceaef40872c59911cce818050dc9da887075cdf2800
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.1
|
Security for svnm 1.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.