gaea-paddleclas


Namegaea-paddleclas JSON
Version 2.5.0.2 PyPI version JSON
download
home_pagehttps://github.com/PaddlePaddle/PaddleClas
SummaryA treasure chest for visual recognition powered by PaddlePaddle.
upload_time2024-04-14 10:10:51
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseApache License 2.0
keywords image-classification image-recognition pretrained-models knowledge-distillation product-recognition autoaugment cutmix randaugment gridmask deit repvgg swin-transformer image-retrieval-system
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PaddleClas wheel package

PaddleClas supports Python wheel package for prediction. At present, PaddleClas wheel supports image classification including ImagetNet1k models and PULC models, but does not support mainbody detection, feature extraction and vector retrieval.

---

## Catalogue

- [1. Installation](#1)
- [2. Quick Start](#2)
   - [2.1 ImageNet1k models](#2.1)
   - [2.2 PULC models](#2.2)
- [3. Definition of Parameters](#3)
- [4. More usage](#4)
   - [4.1 View help information](#4.1)
   - [4.2 Prediction using inference model provide by PaddleClas](#4.2)
   - [4.3 Prediction using local model files](#4.3)
   - [4.4 Prediction by batch](#4.4)
   - [4.5 Prediction of Internet image](#4.5)
   - [4.6 Prediction of `NumPy.array` format image](#4.6)
   - [4.7 Save the prediction result(s)](#4.7)
   - [4.8 Specify the mapping between class id and label name](#4.8)

<a name="1"></a>

## 1. Installation

* **[Recommended]** Installing from PyPI:

```bash
pip3 install paddleclas
```

* Please build and install locally if you need to use the develop branch of PaddleClas to experience the latest functions, or need to redevelop based on PaddleClas. The command is as follows:

```bash
python3 setup.py install
```

<a name="2"></a>

## 2. Quick Start

<a name="2.1"></a>

### 2.1 ImageNet1k models

Using the `ResNet50` model provided by PaddleClas, the following image(`'docs/images/inference_deployment/whl_demo.jpg'`) as an example.

![](../../images/inference_deployment/whl_demo.jpg)

* Python
```python
from paddleclas import PaddleClas
clas = PaddleClas(model_name='ResNet50')
infer_imgs='docs/images/inference_deployment/whl_demo.jpg'
result=clas.predict(infer_imgs)
print(next(result))
```

**Note**: `PaddleClas.predict()` is a `generator`. Therefore you need to use `next()` or `for` call it iteratively. It will perform a prediction by `batch_size` and return the prediction result(s) when called. Examples of returned results are as follows:

```
>>> result
[{'class_ids': [8, 7, 86, 82, 80], 'scores': [0.97968, 0.02028, 3e-05, 1e-05, 0.0], 'label_names': ['hen', 'cock', 'partridge', 'ruffed grouse, partridge, Bonasa umbellus', 'black grouse'], 'filename': 'docs/images/inference_deployment/whl_demo.jpg'}]
```

* CLI
```bash
paddleclas --model_name=ResNet50  --infer_imgs="docs/images/inference_deployment/whl_demo.jpg"
```

```
>>> result
class_ids: [8, 7, 86, 82, 80], scores: [0.97968, 0.02028, 3e-05, 1e-05, 0.0], label_names: ['hen', 'cock', 'partridge', 'ruffed grouse, partridge, Bonasa umbellus', 'black grouse'], filename: docs/images/inference_deployment/whl_demo.jpg
Predict complete!
```

<a name="2.2"></a>

### 2.2 PULC models

PULC integrates various state-of-the-art algorithms such as backbone network, data augmentation and distillation, etc., and finally can automatically obtain a lightweight and high-precision image classification model.

PaddleClas provides a series of test cases, which contain demos of different scenes about people, cars, OCR, etc. Click [here](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip) to download the data.

Prection using the PULC "Human Exists Classification" model provided by PaddleClas:

* Python

```python
import paddleclas
model = paddleclas.PaddleClas(model_name="person_exists")
result = model.predict(input_data="pulc_demo_imgs/person_exists/objects365_01780782.jpg")
print(next(result))
```

```
>>> result
[{'class_ids': [0], 'scores': [0.9955421453341842], 'label_names': ['nobody'], 'filename': 'pulc_demo_imgs/person_exists/objects365_01780782.jpg'}]
```

`Nobody` means there is no one in the image, `someone` means there is someone in the image. Therefore, the prediction result indicates that there is no one in the figure.

**Note**: `model.predict()` is a generator, so `next()` or `for` is needed to call it. This would to predict by batch that length is `batch_size`, default by 1. You can specify the argument `batch_size` and `model_name` when instantiating PaddleClas object, for example: `model = paddleclas.PaddleClas(model_name="person_exists",  batch_size=2)`. Please refer to [Supported Model List](#PULC_Models) for the supported model list.

* CLI

```bash
paddleclas --model_name=person_exists --infer_imgs=pulc_demo_imgs/person_exists/objects365_01780782.jpg
```

```
>>> result
class_ids: [0], scores: [0.9955421453341842], label_names: ['nobody'], filename: pulc_demo_imgs/person_exists/objects365_01780782.jpg
Predict complete!
```

**Note**: The "--infer_imgs" argument specify the image(s) to be predict, and you can also specify a directoy contains images. If use other model, you can specify the `--model_name` argument. Please refer to [Supported Model List](#PULC_Models) for the supported model list.

<a name="PULC_Models"></a>

**Supported Model List**

The name of PULC series models are as follows:

| Name | Intro |
| --- | --- |
| person_exists | Human Exists Classification |
| person_attribute | Pedestrian Attribute Classification |
| safety_helmet | Classification of Wheather Wearing Safety Helmet |
| traffic_sign | Traffic Sign Classification |
| vehicle_attribute | Vehicle Attribute Classification |
| car_exists | Car Exists Classification |
| text_image_orientation | Text Image Orientation Classification |
| textline_orientation | Text-line Orientation Classification |
| language_classification | Language Classification |

Please refer to [Human Exists Classification](../PULC/PULC_person_exists_en.md)、[Pedestrian Attribute Classification](../PULC/PULC_person_attribute_en.md)、[Classification of Wheather Wearing Safety Helmet](../PULC/PULC_safety_helmet_en.md)、[Traffic Sign Classification](../PULC/PULC_traffic_sign_en.md)、[Vehicle Attribute Classification](../PULC/PULC_vehicle_attribute_en.md)、[Car Exists Classification](../PULC/PULC_car_exists_en.md)、[Text Image Orientation Classification](../PULC/PULC_text_image_orientation_en.md)、[Text-line Orientation Classification](../PULC/PULC_textline_orientation_en.md)、[Language Classification](../PULC/PULC_language_classification_en.md) for more information about different scenarios.

<a name="3"></a>

## 3. Definition of Parameters

The following parameters can be specified in Command Line or used as parameters of the constructor when instantiating the PaddleClas object in Python.
* model_name(str): If using inference model based on ImageNet1k provided by Paddle, please specify the model's name by the parameter.
* inference_model_dir(str): Local model files directory, which is valid when `model_name` is not specified. The directory should contain `inference.pdmodel` and `inference.pdiparams`.
* infer_imgs(str): The path of image to be predicted, or the directory containing the image files, or the URL of the image from Internet.
* use_gpu(bool): Whether to use GPU or not.
* gpu_mem(int): GPU memory usages.
* use_tensorrt(bool): Whether to open TensorRT or not. Using it can greatly promote predict preformance.
* enable_mkldnn(bool): Whether enable MKLDNN or not.
* cpu_num_threads(int): Assign number of cpu threads, valid when `--use_gpu` is `False` and `--enable_mkldnn` is `True`.
* batch_size(int): Batch size.
* resize_short(int): Resize the minima between height and width into `resize_short`.
* crop_size(int): Center crop image to `crop_size`.
* topk(int): Print (return) the `topk` prediction results when Topk postprocess is used.
* threshold(float): The threshold of ThreshOutput when postprocess is used.
* class_id_map_file(str): The mapping file between class ID and label.
* save_dir(str): The directory to save the prediction results that can be used as pre-label.

**Note**: If you want to use `Transformer series models`, such as `DeiT_***_384`, `ViT_***_384`, etc., please pay attention to the input size of model, and need to set `resize_short=384`, `resize=384`. The following is a demo.

* CLI:
```bash
from paddleclas import PaddleClas, get_default_confg
paddleclas --model_name=ViT_base_patch16_384 --infer_imgs='docs/images/inference_deployment/whl_demo.jpg' --resize_short=384 --crop_size=384
```

* Python:
```python
from paddleclas import PaddleClas
clas = PaddleClas(model_name='ViT_base_patch16_384', resize_short=384, crop_size=384)
```

<a name="4"></a>

## 4. Usage

PaddleClas provides two ways to use:
1. Python interative programming;
2. Bash command line programming.

<a name="4.1"></a>

### 4.1 View help information

* CLI
```bash
paddleclas -h
```

<a name="4.2"></a>

### 4.2 Prediction using inference model provide by PaddleClas
You can use the inference model provided by PaddleClas to predict, and only need to specify `model_name`. In this case, PaddleClas will automatically download files of specified model and save them in the directory `~/.paddleclas/`.

* Python
```python
from paddleclas import PaddleClas
clas = PaddleClas(model_name='ResNet50')
infer_imgs = 'docs/images/inference_deployment/whl_demo.jpg'
result=clas.predict(infer_imgs)
print(next(result))
```

* CLI
```bash
paddleclas --model_name='ResNet50' --infer_imgs='docs/images/inference_deployment/whl_demo.jpg'
```

<a name="4.3"></a>

### 4.3 Prediction using local model files
You can use the local model files trained by yourself to predict, and only need to specify `inference_model_dir`. Note that the directory must contain `inference.pdmodel` and `inference.pdiparams`.

* Python
```python
from paddleclas import PaddleClas
clas = PaddleClas(inference_model_dir='./inference/')
infer_imgs = 'docs/images/inference_deployment/whl_demo.jpg'
result=clas.predict(infer_imgs)
print(next(result))
```

* CLI
```bash
paddleclas --inference_model_dir='./inference/' --infer_imgs='docs/images/inference_deployment/whl_demo.jpg'
```

<a name="4.4"></a>

### 4.4 Prediction by batch
You can predict by batch, only need to specify `batch_size` when `infer_imgs` is direcotry contain image files.

* Python
```python
from paddleclas import PaddleClas
clas = PaddleClas(model_name='ResNet50', batch_size=2)
infer_imgs = 'docs/images/'
result=clas.predict(infer_imgs)
for r in result:
    print(r)
```

* CLI
```bash
paddleclas --model_name='ResNet50' --infer_imgs='docs/images/' --batch_size 2
```

<a name="4.5"></a>

### 4.5 Prediction of Internet image
You can predict the Internet image, only need to specify URL of Internet image by `infer_imgs`. In this case, the image file will be downloaded and saved in the directory `~/.paddleclas/images/`.

* Python
```python
from paddleclas import PaddleClas
clas = PaddleClas(model_name='ResNet50')
infer_imgs = 'https://raw.githubusercontent.com/paddlepaddle/paddleclas/release/2.2/docs/images/inference_deployment/whl_demo.jpg'
result=clas.predict(infer_imgs)
print(next(result))
```

* CLI
```bash
paddleclas --model_name='ResNet50' --infer_imgs='https://raw.githubusercontent.com/paddlepaddle/paddleclas/release/2.2/docs/images/inference_deployment/whl_demo.jpg'
```

<a name="4.6"></a>

### 4.6 Prediction of NumPy.array format image
In Python code, you can predict the `NumPy.array` format image, only need to use the `infer_imgs` to transfer variable of image data. Note that the models in PaddleClas only support to predict 3 channels image data, and channels order is `RGB`.

* python
```python
import cv2
from paddleclas import PaddleClas
clas = PaddleClas(model_name='ResNet50')
infer_imgs = cv2.imread("docs/en/inference_deployment/whl_deploy_en.md")[:, :, ::-1]
result=clas.predict(infer_imgs)
print(next(result))
```

<a name="4.7"></a>

### 4.7 Save the prediction result(s)
You can save the prediction result(s) as pre-label, only need to use `pre_label_out_dir` to specify the directory to save.

* python
```python
from paddleclas import PaddleClas
clas = PaddleClas(model_name='ResNet50', save_dir='./output_pre_label/')
infer_imgs = 'docs/images/' # it can be infer_imgs folder path which contains all of images you want to predict.
result=clas.predict(infer_imgs)
print(next(result))
```

* CLI
```bash
paddleclas --model_name='ResNet50' --infer_imgs='docs/images/' --save_dir='./output_pre_label/'
```

<a name="4.8"></a>

### 4.8 Specify the mapping between class id and label name
You can specify the mapping between class id and label name, only need to use `class_id_map_file` to specify the mapping file. PaddleClas uses ImageNet1K's mapping by default.

The content format of mapping file shall be:

```
class_id<space>class_name<\n>
```

For example:

```
0 tench, Tinca tinca
1 goldfish, Carassius auratus
2 great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias
......
```

* Python
```python
from paddleclas import PaddleClas
clas = PaddleClas(model_name='ResNet50', class_id_map_file='./ppcls/utils/imagenet1k_label_list.txt')
infer_imgs = 'docs/images/inference_deployment/whl_demo.jpg'
result=clas.predict(infer_imgs)
print(next(result))
```

* CLI
```bash
paddleclas --model_name='ResNet50' --infer_imgs='docs/images/inference_deployment/whl_demo.jpg' --class_id_map_file='./ppcls/utils/imagenet1k_label_list.txt'
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PaddlePaddle/PaddleClas",
    "name": "gaea-paddleclas",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "image-classification, image-recognition, pretrained-models, knowledge-distillation, product-recognition, autoaugment, cutmix, randaugment, gridmask, deit, repvgg, swin-transformer, image-retrieval-system",
    "author": null,
    "author_email": null,
    "download_url": "https://github.com/PaddlePaddle/PaddleClas.git",
    "platform": null,
    "description": "# PaddleClas wheel package\n\nPaddleClas supports Python wheel package for prediction. At present, PaddleClas wheel supports image classification including ImagetNet1k models and PULC models, but does not support mainbody detection, feature extraction and vector retrieval.\n\n---\n\n## Catalogue\n\n- [1. Installation](#1)\n- [2. Quick Start](#2)\n   - [2.1 ImageNet1k models](#2.1)\n   - [2.2 PULC models](#2.2)\n- [3. Definition of Parameters](#3)\n- [4. More usage](#4)\n   - [4.1 View help information](#4.1)\n   - [4.2 Prediction using inference model provide by PaddleClas](#4.2)\n   - [4.3 Prediction using local model files](#4.3)\n   - [4.4 Prediction by batch](#4.4)\n   - [4.5 Prediction of Internet image](#4.5)\n   - [4.6 Prediction of `NumPy.array` format image](#4.6)\n   - [4.7 Save the prediction result(s)](#4.7)\n   - [4.8 Specify the mapping between class id and label name](#4.8)\n\n<a name=\"1\"></a>\n\n## 1. Installation\n\n* **[Recommended]** Installing from PyPI:\n\n```bash\npip3 install paddleclas\n```\n\n* Please build and install locally if you need to use the develop branch of PaddleClas to experience the latest functions, or need to redevelop based on PaddleClas. The command is as follows:\n\n```bash\npython3 setup.py install\n```\n\n<a name=\"2\"></a>\n\n## 2. Quick Start\n\n<a name=\"2.1\"></a>\n\n### 2.1 ImageNet1k models\n\nUsing the `ResNet50` model provided by PaddleClas, the following image(`'docs/images/inference_deployment/whl_demo.jpg'`) as an example.\n\n![](../../images/inference_deployment/whl_demo.jpg)\n\n* Python\n```python\nfrom paddleclas import PaddleClas\nclas = PaddleClas(model_name='ResNet50')\ninfer_imgs='docs/images/inference_deployment/whl_demo.jpg'\nresult=clas.predict(infer_imgs)\nprint(next(result))\n```\n\n**Note**: `PaddleClas.predict()` is a `generator`. Therefore you need to use `next()` or `for` call it iteratively. It will perform a prediction by `batch_size` and return the prediction result(s) when called. Examples of returned results are as follows:\n\n```\n>>> result\n[{'class_ids': [8, 7, 86, 82, 80], 'scores': [0.97968, 0.02028, 3e-05, 1e-05, 0.0], 'label_names': ['hen', 'cock', 'partridge', 'ruffed grouse, partridge, Bonasa umbellus', 'black grouse'], 'filename': 'docs/images/inference_deployment/whl_demo.jpg'}]\n```\n\n* CLI\n```bash\npaddleclas --model_name=ResNet50  --infer_imgs=\"docs/images/inference_deployment/whl_demo.jpg\"\n```\n\n```\n>>> result\nclass_ids: [8, 7, 86, 82, 80], scores: [0.97968, 0.02028, 3e-05, 1e-05, 0.0], label_names: ['hen', 'cock', 'partridge', 'ruffed grouse, partridge, Bonasa umbellus', 'black grouse'], filename: docs/images/inference_deployment/whl_demo.jpg\nPredict complete!\n```\n\n<a name=\"2.2\"></a>\n\n### 2.2 PULC models\n\nPULC integrates various state-of-the-art algorithms such as backbone network, data augmentation and distillation, etc., and finally can automatically obtain a lightweight and high-precision image classification model.\n\nPaddleClas provides a series of test cases, which contain demos of different scenes about people, cars, OCR, etc. Click [here](https://paddleclas.bj.bcebos.com/data/PULC/pulc_demo_imgs.zip) to download the data.\n\nPrection using the PULC \"Human Exists Classification\" model provided by PaddleClas:\n\n* Python\n\n```python\nimport paddleclas\nmodel = paddleclas.PaddleClas(model_name=\"person_exists\")\nresult = model.predict(input_data=\"pulc_demo_imgs/person_exists/objects365_01780782.jpg\")\nprint(next(result))\n```\n\n```\n>>> result\n[{'class_ids': [0], 'scores': [0.9955421453341842], 'label_names': ['nobody'], 'filename': 'pulc_demo_imgs/person_exists/objects365_01780782.jpg'}]\n```\n\n`Nobody` means there is no one in the image, `someone` means there is someone in the image. Therefore, the prediction result indicates that there is no one in the figure.\n\n**Note**: `model.predict()` is a generator, so `next()` or `for` is needed to call it. This would to predict by batch that length is `batch_size`, default by 1. You can specify the argument `batch_size` and `model_name` when instantiating PaddleClas object, for example: `model = paddleclas.PaddleClas(model_name=\"person_exists\",  batch_size=2)`. Please refer to [Supported Model List](#PULC_Models) for the supported model list.\n\n* CLI\n\n```bash\npaddleclas --model_name=person_exists --infer_imgs=pulc_demo_imgs/person_exists/objects365_01780782.jpg\n```\n\n```\n>>> result\nclass_ids: [0], scores: [0.9955421453341842], label_names: ['nobody'], filename: pulc_demo_imgs/person_exists/objects365_01780782.jpg\nPredict complete!\n```\n\n**Note**: The \"--infer_imgs\" argument specify the image(s) to be predict, and you can also specify a directoy contains images. If use other model, you can specify the `--model_name` argument. Please refer to [Supported Model List](#PULC_Models) for the supported model list.\n\n<a name=\"PULC_Models\"></a>\n\n**Supported Model List**\n\nThe name of PULC series models are as follows:\n\n| Name | Intro |\n| --- | --- |\n| person_exists | Human Exists Classification |\n| person_attribute | Pedestrian Attribute Classification |\n| safety_helmet | Classification of Wheather Wearing Safety Helmet |\n| traffic_sign | Traffic Sign Classification |\n| vehicle_attribute | Vehicle Attribute Classification |\n| car_exists | Car Exists Classification |\n| text_image_orientation | Text Image Orientation Classification |\n| textline_orientation | Text-line Orientation Classification |\n| language_classification | Language Classification |\n\nPlease refer to [Human Exists Classification](../PULC/PULC_person_exists_en.md)\u3001[Pedestrian Attribute Classification](../PULC/PULC_person_attribute_en.md)\u3001[Classification of Wheather Wearing Safety Helmet](../PULC/PULC_safety_helmet_en.md)\u3001[Traffic Sign Classification](../PULC/PULC_traffic_sign_en.md)\u3001[Vehicle Attribute Classification](../PULC/PULC_vehicle_attribute_en.md)\u3001[Car Exists Classification](../PULC/PULC_car_exists_en.md)\u3001[Text Image Orientation Classification](../PULC/PULC_text_image_orientation_en.md)\u3001[Text-line Orientation Classification](../PULC/PULC_textline_orientation_en.md)\u3001[Language Classification](../PULC/PULC_language_classification_en.md) for more information about different scenarios.\n\n<a name=\"3\"></a>\n\n## 3. Definition of Parameters\n\nThe following parameters can be specified in Command Line or used as parameters of the constructor when instantiating the PaddleClas object in Python.\n* model_name(str): If using inference model based on ImageNet1k provided by Paddle, please specify the model's name by the parameter.\n* inference_model_dir(str): Local model files directory, which is valid when `model_name` is not specified. The directory should contain `inference.pdmodel` and `inference.pdiparams`.\n* infer_imgs(str): The path of image to be predicted, or the directory containing the image files, or the URL of the image from Internet.\n* use_gpu(bool): Whether to use GPU or not.\n* gpu_mem(int): GPU memory usages.\n* use_tensorrt(bool): Whether to open TensorRT or not. Using it can greatly promote predict preformance.\n* enable_mkldnn(bool): Whether enable MKLDNN or not.\n* cpu_num_threads(int): Assign number of cpu threads, valid when `--use_gpu` is `False` and `--enable_mkldnn` is `True`.\n* batch_size(int): Batch size.\n* resize_short(int): Resize the minima between height and width into `resize_short`.\n* crop_size(int): Center crop image to `crop_size`.\n* topk(int): Print (return) the `topk` prediction results when Topk postprocess is used.\n* threshold(float): The threshold of ThreshOutput when postprocess is used.\n* class_id_map_file(str): The mapping file between class ID and label.\n* save_dir(str): The directory to save the prediction results that can be used as pre-label.\n\n**Note**: If you want to use `Transformer series models`, such as `DeiT_***_384`, `ViT_***_384`, etc., please pay attention to the input size of model, and need to set `resize_short=384`, `resize=384`. The following is a demo.\n\n* CLI:\n```bash\nfrom paddleclas import PaddleClas, get_default_confg\npaddleclas --model_name=ViT_base_patch16_384 --infer_imgs='docs/images/inference_deployment/whl_demo.jpg' --resize_short=384 --crop_size=384\n```\n\n* Python:\n```python\nfrom paddleclas import PaddleClas\nclas = PaddleClas(model_name='ViT_base_patch16_384', resize_short=384, crop_size=384)\n```\n\n<a name=\"4\"></a>\n\n## 4. Usage\n\nPaddleClas provides two ways to use:\n1. Python interative programming;\n2. Bash command line programming.\n\n<a name=\"4.1\"></a>\n\n### 4.1 View help information\n\n* CLI\n```bash\npaddleclas -h\n```\n\n<a name=\"4.2\"></a>\n\n### 4.2 Prediction using inference model provide by PaddleClas\nYou can use the inference model provided by PaddleClas to predict, and only need to specify `model_name`. In this case, PaddleClas will automatically download files of specified model and save them in the directory `~/.paddleclas/`.\n\n* Python\n```python\nfrom paddleclas import PaddleClas\nclas = PaddleClas(model_name='ResNet50')\ninfer_imgs = 'docs/images/inference_deployment/whl_demo.jpg'\nresult=clas.predict(infer_imgs)\nprint(next(result))\n```\n\n* CLI\n```bash\npaddleclas --model_name='ResNet50' --infer_imgs='docs/images/inference_deployment/whl_demo.jpg'\n```\n\n<a name=\"4.3\"></a>\n\n### 4.3 Prediction using local model files\nYou can use the local model files trained by yourself to predict, and only need to specify `inference_model_dir`. Note that the directory must contain `inference.pdmodel` and `inference.pdiparams`.\n\n* Python\n```python\nfrom paddleclas import PaddleClas\nclas = PaddleClas(inference_model_dir='./inference/')\ninfer_imgs = 'docs/images/inference_deployment/whl_demo.jpg'\nresult=clas.predict(infer_imgs)\nprint(next(result))\n```\n\n* CLI\n```bash\npaddleclas --inference_model_dir='./inference/' --infer_imgs='docs/images/inference_deployment/whl_demo.jpg'\n```\n\n<a name=\"4.4\"></a>\n\n### 4.4 Prediction by batch\nYou can predict by batch, only need to specify `batch_size` when `infer_imgs` is direcotry contain image files.\n\n* Python\n```python\nfrom paddleclas import PaddleClas\nclas = PaddleClas(model_name='ResNet50', batch_size=2)\ninfer_imgs = 'docs/images/'\nresult=clas.predict(infer_imgs)\nfor r in result:\n    print(r)\n```\n\n* CLI\n```bash\npaddleclas --model_name='ResNet50' --infer_imgs='docs/images/' --batch_size 2\n```\n\n<a name=\"4.5\"></a>\n\n### 4.5 Prediction of Internet image\nYou can predict the Internet image, only need to specify URL of Internet image by `infer_imgs`. In this case, the image file will be downloaded and saved in the directory `~/.paddleclas/images/`.\n\n* Python\n```python\nfrom paddleclas import PaddleClas\nclas = PaddleClas(model_name='ResNet50')\ninfer_imgs = 'https://raw.githubusercontent.com/paddlepaddle/paddleclas/release/2.2/docs/images/inference_deployment/whl_demo.jpg'\nresult=clas.predict(infer_imgs)\nprint(next(result))\n```\n\n* CLI\n```bash\npaddleclas --model_name='ResNet50' --infer_imgs='https://raw.githubusercontent.com/paddlepaddle/paddleclas/release/2.2/docs/images/inference_deployment/whl_demo.jpg'\n```\n\n<a name=\"4.6\"></a>\n\n### 4.6 Prediction of NumPy.array format image\nIn Python code, you can predict the `NumPy.array` format image, only need to use the `infer_imgs` to transfer variable of image data. Note that the models in PaddleClas only support to predict 3 channels image data, and channels order is `RGB`.\n\n* python\n```python\nimport cv2\nfrom paddleclas import PaddleClas\nclas = PaddleClas(model_name='ResNet50')\ninfer_imgs = cv2.imread(\"docs/en/inference_deployment/whl_deploy_en.md\")[:, :, ::-1]\nresult=clas.predict(infer_imgs)\nprint(next(result))\n```\n\n<a name=\"4.7\"></a>\n\n### 4.7 Save the prediction result(s)\nYou can save the prediction result(s) as pre-label, only need to use `pre_label_out_dir` to specify the directory to save.\n\n* python\n```python\nfrom paddleclas import PaddleClas\nclas = PaddleClas(model_name='ResNet50', save_dir='./output_pre_label/')\ninfer_imgs = 'docs/images/' # it can be infer_imgs folder path which contains all of images you want to predict.\nresult=clas.predict(infer_imgs)\nprint(next(result))\n```\n\n* CLI\n```bash\npaddleclas --model_name='ResNet50' --infer_imgs='docs/images/' --save_dir='./output_pre_label/'\n```\n\n<a name=\"4.8\"></a>\n\n### 4.8 Specify the mapping between class id and label name\nYou can specify the mapping between class id and label name, only need to use `class_id_map_file` to specify the mapping file. PaddleClas uses ImageNet1K's mapping by default.\n\nThe content format of mapping file shall be:\n\n```\nclass_id<space>class_name<\\n>\n```\n\nFor example:\n\n```\n0 tench, Tinca tinca\n1 goldfish, Carassius auratus\n2 great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias\n......\n```\n\n* Python\n```python\nfrom paddleclas import PaddleClas\nclas = PaddleClas(model_name='ResNet50', class_id_map_file='./ppcls/utils/imagenet1k_label_list.txt')\ninfer_imgs = 'docs/images/inference_deployment/whl_demo.jpg'\nresult=clas.predict(infer_imgs)\nprint(next(result))\n```\n\n* CLI\n```bash\npaddleclas --model_name='ResNet50' --infer_imgs='docs/images/inference_deployment/whl_demo.jpg' --class_id_map_file='./ppcls/utils/imagenet1k_label_list.txt'\n```\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "A treasure chest for visual recognition powered by PaddlePaddle.",
    "version": "2.5.0.2",
    "project_urls": {
        "Download": "https://github.com/PaddlePaddle/PaddleClas.git",
        "Homepage": "https://github.com/PaddlePaddle/PaddleClas"
    },
    "split_keywords": [
        "image-classification",
        " image-recognition",
        " pretrained-models",
        " knowledge-distillation",
        " product-recognition",
        " autoaugment",
        " cutmix",
        " randaugment",
        " gridmask",
        " deit",
        " repvgg",
        " swin-transformer",
        " image-retrieval-system"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9840546ee3c319f70958031fbbe01f7eb5d3397fcc1098b4ddb959dff7895eed",
                "md5": "d304192ce1757c79f97b6f08fc07e8f6",
                "sha256": "afce89cabf7dcb8eb6c8261368a9247f021a897282841a4538bbf620fec4cf89"
            },
            "downloads": -1,
            "filename": "gaea_paddleclas-2.5.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d304192ce1757c79f97b6f08fc07e8f6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 498623,
            "upload_time": "2024-04-14T10:10:51",
            "upload_time_iso_8601": "2024-04-14T10:10:51.388635Z",
            "url": "https://files.pythonhosted.org/packages/98/40/546ee3c319f70958031fbbe01f7eb5d3397fcc1098b4ddb959dff7895eed/gaea_paddleclas-2.5.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-14 10:10:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PaddlePaddle",
    "github_project": "PaddleClas",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "gaea-paddleclas"
}
        
Elapsed time: 0.22989s