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

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  

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.0.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.0-py3-none-any.whl (79.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sensitiveimgdetect-0.0.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f20c4dd018a81c28a4289b622cd0a5e2e02ced98e7718e8a4ba1f4b481a4672c
MD5 e4685bdb6c216743758af8417e966b1f
BLAKE2b-256 2d36b2466c53b340d8244c33b7cc2863a54c2860973cd271d40ab737695e1424

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for SensitiveImgDetect-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3acf2e959dce0268a098e291c17e1b7c119e0353509c410696d0ce0cb72dcc42
MD5 407c956ef192304cd61afd31da61d3ab
BLAKE2b-256 0659be14e5edcbe2a0891f0d3d080ddfc75e07583ab7949a1f660a3518463da0

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