SensitiveImgDetect 0.0.2
A package used to detect sensitive image

# SensitiveImgDetect  

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


## Installation

You can install this package using pip:

```bash
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).

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

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

## Model Perference  
```shell
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  
```shell
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  
```shell
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
```