sensitive-image 0.1.0
A package used to detect sensitive image

# SensitiveImageDetect  

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

## Installation

You can install this package using pip:

```bash
pip install SensitiveImageDetect

## 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 torchvision 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).

```python
from SensitiveImageDetect 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:

```python
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:

```python
# 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:

```python
# 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:

```python
# 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}")
```