Browse Source

!345 remove ip address, procces raise error and deal with gray image

Merge pull request !345 from ZhidanLiu/master
tags/v1.8.0
i-robot Gitee 3 years ago
parent
commit
d8819c55e2
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 11 additions and 6 deletions
  1. +2
    -2
      examples/natural_robustness/ocr_evaluate/cnn_ctc/src/dataset.py
  2. +6
    -3
      examples/natural_robustness/ocr_evaluate/generate_adv_samples.py
  3. +1
    -1
      examples/natural_robustness/ocr_evaluate/对OCR模型CNN-CTC的鲁棒性评测.md
  4. +2
    -0
      examples/natural_robustness/serving/server/perturbation/servable_config.py

+ 2
- 2
examples/natural_robustness/ocr_evaluate/cnn_ctc/src/dataset.py View File

@@ -22,8 +22,8 @@ import numpy as np
from PIL import Image
import lmdb
from mindspore.communication.management import get_rank, get_group_size
from src.model_utils.config import config
from src.util import CTCLabelConverter
from .model_utils.config import config
from .util import CTCLabelConverter


class NormalizePAD:


+ 6
- 3
examples/natural_robustness/ocr_evaluate/generate_adv_samples.py View File

@@ -88,7 +88,7 @@ def generate_adv_iii5t_3000(lmdb_paths, lmdb_save_path, perturb_config):

print(f'num of samples in IIIT dataset: {len(filtered_index_list)}')

client = Client("10.113.216.54:5500", "perturbation", "natural_perturbation")
client = Client("0.0.0.0:5500", "perturbation", "natural_perturbation")
start_time = time.time()
result = client.infer(instances)
end_time = time.time()
@@ -101,9 +101,12 @@ def generate_adv_iii5t_3000(lmdb_paths, lmdb_save_path, perturb_config):
for i, index in enumerate(filtered_index_list):
try:
file_names = result[i]['file_names'].split(';')
except:
except KeyError:
error_msg = result[i]
raise ValueError(error_msg)
msg = 'serving failed to generate the {}th image in origin dataset with ' \
'error messages: {}'.format(i, error_msg)
print(KeyError(msg))
continue

length = result[i]['file_length'].tolist()
before = 0


+ 1
- 1
examples/natural_robustness/ocr_evaluate/对OCR模型CNN-CTC的鲁棒性评测.md View File

@@ -209,7 +209,7 @@
3. 请求自然扰动serving服务,并保存serving返回的数据
```python
client = Client("10.113.216.54:5500", "perturbation", "natural_perturbation")
client = Client("0.0.0.0:5500", "perturbation", "natural_perturbation")
start_time = time.time()
result = client.infer(instances)
end_time = time.time()


+ 2
- 0
examples/natural_robustness/serving/server/perturbation/servable_config.py View File

@@ -47,6 +47,8 @@ def check_inputs(img, perturb_config, methods_number, outputs_number):
if not np.any(img):
raise ValueError("img cannot be empty.")
img = Image.open(BytesIO(img))
if img.mode == "L":
img = img.convert('RGB')
img = cv2.cvtColor(np.asarray(img), cv2.COLOR_RGB2BGR)

config = json.loads(perturb_config)


Loading…
Cancel
Save