diff --git a/examples/natural_robustness/ocr_evaluate/cnn_ctc/src/dataset.py b/examples/natural_robustness/ocr_evaluate/cnn_ctc/src/dataset.py index 3d78c89..2c918e7 100644 --- a/examples/natural_robustness/ocr_evaluate/cnn_ctc/src/dataset.py +++ b/examples/natural_robustness/ocr_evaluate/cnn_ctc/src/dataset.py @@ -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: diff --git a/examples/natural_robustness/ocr_evaluate/generate_adv_samples.py b/examples/natural_robustness/ocr_evaluate/generate_adv_samples.py index 62b87df..bd4ba41 100644 --- a/examples/natural_robustness/ocr_evaluate/generate_adv_samples.py +++ b/examples/natural_robustness/ocr_evaluate/generate_adv_samples.py @@ -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 diff --git a/examples/natural_robustness/ocr_evaluate/对OCR模型CNN-CTC的鲁棒性评测.md b/examples/natural_robustness/ocr_evaluate/对OCR模型CNN-CTC的鲁棒性评测.md index 97219ff..dbd1f26 100644 --- a/examples/natural_robustness/ocr_evaluate/对OCR模型CNN-CTC的鲁棒性评测.md +++ b/examples/natural_robustness/ocr_evaluate/对OCR模型CNN-CTC的鲁棒性评测.md @@ -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() diff --git a/examples/natural_robustness/serving/server/perturbation/servable_config.py b/examples/natural_robustness/serving/server/perturbation/servable_config.py index 36772f9..8752c57 100644 --- a/examples/natural_robustness/serving/server/perturbation/servable_config.py +++ b/examples/natural_robustness/serving/server/perturbation/servable_config.py @@ -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)