Skip to main content

A package used to detect sensitive image

Project description

SensitiveImgDetect

This package provides a way to load a trained PyTorch model.

Installation

You can install this package using pip:

pip install SensitiveImgDetect

## Overview

The `Detect` class is designed for image classification tasks, allowing users to predict the class of single or multiple images using a pre-trained model. This document provides an overview of how to initialize and use the class, including example code snippets.

## Installation

Before using the `Detect` class, ensure that you have installed the necessary libraries:

```bash
pip install torch pillow torchvision

Initialization

To use the Detect class, you need to initialize it. The class constructor allows you to specify the device for computation (CPU or GPU).

from SensitiveImgDetect import Detect 

# Initialize the Detect class
detector = Detect(device='cuda')  # Use 'cpu' if you don't have CUDA

Methods

1. Detecting the Class of a Single Image

Method: detect_single_type

Description: Predicts the class label for a single image.

Parameters:

  • img: An image object (PIL Image).

Returns: A string representing the predicted class label.

Example Usage:

from PIL import Image

# Load an image
img = Image.open("path_to_your_image.jpg")

# Predict the class label
predicted_label = detector.detect_single_type(img)
print(f"The predicted class for the single image is: {predicted_label}")

2. Detecting Class Probabilities for a Single Image

Method: detect_single_prob

Description: Predicts the class probabilities for a single image.

Parameters:

  • img: An image object (PIL Image).

Returns: A dictionary with class labels and their corresponding probabilities.

Example Usage:

# Predict class probabilities
predicted_probs = detector.detect_single_prob(img)
print("Class probabilities for the image:")
for class_label, probability in predicted_probs.items():
    print(f"{class_label}: {probability}")

3. Detecting Classes for a List of Images

Method: detect_list_type

Description: Predicts the class labels for a list of images.

Parameters:

  • img_list: A list of image objects (PIL Images).

Returns: A list of predicted class labels.

Example Usage:

# Load multiple images
images = [Image.open("image_1.jpg"), Image.open("image_2.jpg")]

# Predict class labels for the list of images
predicted_labels = detector.detect_list_type(images)
print("Predicted classes for the list of images:")
print(predicted_labels)

4. Detecting Class Probabilities for a List of Images

Method: detect_list_prob

Description: Predicts the class probabilities for a list of images.

Parameters:

  • img_list: A list of image objects (PIL Images).

Returns: A list of dictionaries with class labels and their corresponding probabilities.

Example Usage:

# Predict class probabilities for the list of images
predicted_probs_list = detector.detect_list_prob(images)
for index, probs in enumerate(predicted_probs_list):
    print(f"Probabilities for image {index + 1}:")
    for class_label, probability in probs.items():
        print(f"{class_label}: {probability}")

Model Perference

Class: carton  
  Precision: 0.95  
  Recall: 0.95  
Class: other  
  Precision: 0.92  
  Recall: 0.82  
Class: politic  
  Precision: 0.79  
  Recall: 0.93  
Class: sex  
  Precision: 0.95  
  Recall: 0.88  
Overall Accuracy: 0.89  

version

model_v1

  • base model
Class: carton
  Precision: 0.95
  Recall: 0.95
Class: other
  Precision: 0.92
  Recall: 0.82
Class: politic
  Precision: 0.79
  Recall: 0.93
Class: sex
  Precision: 0.95
  Recall: 0.88
Overall Accuracy: 0.89

model_v2

  • add some data
Class: carton
  Precision: 0.92
  Recall: 0.88
Class: other
  Precision: 0.93
  Recall: 0.93
Class: politic
  Precision: 0.88
  Recall: 0.88
Class: sex
  Precision: 0.86
  Recall: 0.90
Overall Accuracy: 0.89

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sensitiveimgdetect-0.0.2.tar.gz (79.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SensitiveImgDetect-0.0.2-py3-none-any.whl (79.1 MB view details)

Uploaded Python 3

File details

Details for the file sensitiveimgdetect-0.0.2.tar.gz.

File metadata

  • Download URL: sensitiveimgdetect-0.0.2.tar.gz
  • Upload date:
  • Size: 79.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.10

File hashes

Hashes for sensitiveimgdetect-0.0.2.tar.gz
Algorithm Hash digest
SHA256 16e7655205d5bd8e9b4d512b36bb0e7c94aae2df4de21e715b0084a75436d52c
MD5 cc5261ba1d75bc4d2294fda3d7db853b
BLAKE2b-256 234b2b10c1a4a0b99a5964e3b38d9f77c0c965c66344a16eee998053486efacd

See more details on using hashes here.

File details

Details for the file SensitiveImgDetect-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for SensitiveImgDetect-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3f830dd65ebacc519efccbce6a44dc5e3b90a1e7bd96e1350f968c7089239ea4
MD5 5bf03c8062323118a7559f845ff2c007
BLAKE2b-256 38e134440c0888e8167e3731a385bbf048c5655183f76b111e85851011a55e62

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page