diff --git a/ppocr/data/imaug/operators.py b/ppocr/data/imaug/operators.py index e1d192d09c..728314aade 100644 --- a/ppocr/data/imaug/operators.py +++ b/ppocr/data/imaug/operators.py @@ -20,7 +20,6 @@ from __future__ import unicode_literals import sys -import six import cv2 import numpy as np import math @@ -39,14 +38,9 @@ def __init__( def __call__(self, data): img = data["image"] - if six.PY2: - assert ( - type(img) is str and len(img) > 0 - ), "invalid input 'img' in DecodeImage" - else: - assert ( - type(img) is bytes and len(img) > 0 - ), "invalid input 'img' in DecodeImage" + assert ( + type(img) is bytes and len(img) > 0 + ), "invalid input 'img' in DecodeImage" img = np.frombuffer(img, dtype="uint8") if self.ignore_orientation: img = cv2.imdecode(img, cv2.IMREAD_IGNORE_ORIENTATION | cv2.IMREAD_COLOR) diff --git a/ppocr/data/imaug/randaugment.py b/ppocr/data/imaug/randaugment.py index 5f29f325d5..588fb7b1d1 100644 --- a/ppocr/data/imaug/randaugment.py +++ b/ppocr/data/imaug/randaugment.py @@ -20,7 +20,6 @@ from PIL import Image, ImageEnhance, ImageOps import numpy as np import random -import six class RawRandAugment(object): @@ -117,10 +116,7 @@ class RandAugment(RawRandAugment): def __init__(self, prob=0.5, *args, **kwargs): self.prob = prob - if six.PY2: - super(RandAugment, self).__init__(*args, **kwargs) - else: - super().__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def __call__(self, data): if np.random.rand() > self.prob: @@ -130,10 +126,7 @@ def __call__(self, data): img = np.ascontiguousarray(img) img = Image.fromarray(img) - if six.PY2: - img = super(RandAugment, self).__call__(img) - else: - img = super().__call__(img) + img = super().__call__(img) if isinstance(img, Image.Image): img = np.asarray(img) diff --git a/ppocr/data/imaug/table_ops.py b/ppocr/data/imaug/table_ops.py index 83b119cd51..cc244dd39c 100644 --- a/ppocr/data/imaug/table_ops.py +++ b/ppocr/data/imaug/table_ops.py @@ -20,7 +20,6 @@ from __future__ import unicode_literals import sys -import six import cv2 import numpy as np diff --git a/ppocr/data/lmdb_dataset.py b/ppocr/data/lmdb_dataset.py index 778adaa945..6472e70cd5 100644 --- a/ppocr/data/lmdb_dataset.py +++ b/ppocr/data/lmdb_dataset.py @@ -12,12 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np +import io import os from paddle.io import Dataset import lmdb import cv2 import string -import six import pickle from PIL import Image @@ -158,7 +158,7 @@ def __len__(self): class LMDBDataSetSR(LMDBDataSet): def buf2PIL(self, txn, key, type="RGB"): imgbuf = txn.get(key) - buf = six.BytesIO() + buf = io.BytesIO() buf.write(imgbuf) buf.seek(0) im = Image.open(buf).convert(type) diff --git a/ppocr/utils/save_load.py b/ppocr/utils/save_load.py index afd7c6ad97..aa4064ca2e 100644 --- a/ppocr/utils/save_load.py +++ b/ppocr/utils/save_load.py @@ -19,7 +19,6 @@ import errno import os import pickle -import six import json import paddle @@ -69,9 +68,7 @@ def load_model(config, model, optimizer=None, model_type="det"): if checkpoints: if os.path.exists(os.path.join(checkpoints, "metric.states")): with open(os.path.join(checkpoints, "metric.states"), "rb") as f: - states_dict = ( - pickle.load(f) if six.PY2 else pickle.load(f, encoding="latin1") - ) + states_dict = pickle.load(f, encoding="latin1") best_model_dict = states_dict.get("best_model_dict", {}) if "epoch" in states_dict: best_model_dict["start_epoch"] = states_dict["epoch"] + 1 @@ -140,9 +137,7 @@ def load_model(config, model, optimizer=None, model_type="det"): if os.path.exists(checkpoints + ".states"): with open(checkpoints + ".states", "rb") as f: - states_dict = ( - pickle.load(f) if six.PY2 else pickle.load(f, encoding="latin1") - ) + states_dict = pickle.load(f, encoding="latin1") best_model_dict = states_dict.get("best_model_dict", {}) best_model_dict["acc"] = 0.0 if "epoch" in states_dict: diff --git a/pyproject.toml b/pyproject.toml index 259faa432b..74ec8f1260 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,6 @@ classifiers = [ dependencies = [ "shapely", "scikit-image", - "six", "pyclipper", "lmdb", "tqdm", diff --git a/requirements.txt b/requirements.txt index cd8a7f88fd..87d0d1c11e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ shapely scikit-image -six pyclipper lmdb tqdm diff --git a/test_tipc/supplementary/data.py b/test_tipc/supplementary/data.py index 5fe538d6b1..a31d35dc7a 100644 --- a/test_tipc/supplementary/data.py +++ b/test_tipc/supplementary/data.py @@ -44,14 +44,9 @@ def __init__(self, img_mode="RGB", channel_first=False, **kwargs): def __call__(self, data): img = data["image"] - if six.PY2: - assert ( - type(img) is str and len(img) > 0 - ), "invalid input 'img' in DecodeImage" - else: - assert ( - type(img) is bytes and len(img) > 0 - ), "invalid input 'img' in DecodeImage" + assert ( + type(img) is bytes and len(img) > 0 + ), "invalid input 'img' in DecodeImage" img = np.frombuffer(img, dtype="uint8") img = cv2.imdecode(img, 1) if img is None: diff --git a/test_tipc/supplementary/utils.py b/test_tipc/supplementary/utils.py index 8b21490dec..ffd61fae62 100644 --- a/test_tipc/supplementary/utils.py +++ b/test_tipc/supplementary/utils.py @@ -132,9 +132,7 @@ def load_model(config, model, optimizer=None): if os.path.exists(checkpoints + ".states"): with open(checkpoints + ".states", "rb") as f: - states_dict = ( - pickle.load(f) if six.PY2 else pickle.load(f, encoding="latin1") - ) + states_dict = pickle.load(f, encoding="latin1") best_model_dict = states_dict.get("best_model_dict", {}) if "epoch" in states_dict: best_model_dict["start_epoch"] = states_dict["epoch"] + 1