Skip to content

Commit 64e1e3a

Browse files
committed
Remove Python 2 compatibility dependency
1 parent 9308d5e commit 64e1e3a

File tree

9 files changed

+13
-41
lines changed

9 files changed

+13
-41
lines changed

ppocr/data/imaug/operators.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from __future__ import unicode_literals
2121

2222
import sys
23-
import six
2423
import cv2
2524
import numpy as np
2625
import math
@@ -39,14 +38,9 @@ def __init__(
3938

4039
def __call__(self, data):
4140
img = data["image"]
42-
if six.PY2:
43-
assert (
44-
type(img) is str and len(img) > 0
45-
), "invalid input 'img' in DecodeImage"
46-
else:
47-
assert (
48-
type(img) is bytes and len(img) > 0
49-
), "invalid input 'img' in DecodeImage"
41+
assert (
42+
type(img) is bytes and len(img) > 0
43+
), "invalid input 'img' in DecodeImage"
5044
img = np.frombuffer(img, dtype="uint8")
5145
if self.ignore_orientation:
5246
img = cv2.imdecode(img, cv2.IMREAD_IGNORE_ORIENTATION | cv2.IMREAD_COLOR)

ppocr/data/imaug/randaugment.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from PIL import Image, ImageEnhance, ImageOps
2121
import numpy as np
2222
import random
23-
import six
2423

2524

2625
class RawRandAugment(object):
@@ -117,10 +116,7 @@ class RandAugment(RawRandAugment):
117116

118117
def __init__(self, prob=0.5, *args, **kwargs):
119118
self.prob = prob
120-
if six.PY2:
121-
super(RandAugment, self).__init__(*args, **kwargs)
122-
else:
123-
super().__init__(*args, **kwargs)
119+
super().__init__(*args, **kwargs)
124120

125121
def __call__(self, data):
126122
if np.random.rand() > self.prob:
@@ -130,10 +126,7 @@ def __call__(self, data):
130126
img = np.ascontiguousarray(img)
131127
img = Image.fromarray(img)
132128

133-
if six.PY2:
134-
img = super(RandAugment, self).__call__(img)
135-
else:
136-
img = super().__call__(img)
129+
img = super().__call__(img)
137130

138131
if isinstance(img, Image.Image):
139132
img = np.asarray(img)

ppocr/data/imaug/table_ops.py

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from __future__ import unicode_literals
2121

2222
import sys
23-
import six
2423
import cv2
2524
import numpy as np
2625

ppocr/data/lmdb_dataset.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import numpy as np
15+
import io
1516
import os
1617
from paddle.io import Dataset
1718
import lmdb
1819
import cv2
1920
import string
20-
import six
2121
import pickle
2222
from PIL import Image
2323

@@ -158,7 +158,7 @@ def __len__(self):
158158
class LMDBDataSetSR(LMDBDataSet):
159159
def buf2PIL(self, txn, key, type="RGB"):
160160
imgbuf = txn.get(key)
161-
buf = six.BytesIO()
161+
buf = io.BytesIO()
162162
buf.write(imgbuf)
163163
buf.seek(0)
164164
im = Image.open(buf).convert(type)

ppocr/utils/save_load.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import errno
2020
import os
2121
import pickle
22-
import six
2322
import json
2423

2524
import paddle
@@ -69,9 +68,7 @@ def load_model(config, model, optimizer=None, model_type="det"):
6968
if checkpoints:
7069
if os.path.exists(os.path.join(checkpoints, "metric.states")):
7170
with open(os.path.join(checkpoints, "metric.states"), "rb") as f:
72-
states_dict = (
73-
pickle.load(f) if six.PY2 else pickle.load(f, encoding="latin1")
74-
)
71+
states_dict = pickle.load(f, encoding="latin1")
7572
best_model_dict = states_dict.get("best_model_dict", {})
7673
if "epoch" in states_dict:
7774
best_model_dict["start_epoch"] = states_dict["epoch"] + 1
@@ -140,9 +137,7 @@ def load_model(config, model, optimizer=None, model_type="det"):
140137

141138
if os.path.exists(checkpoints + ".states"):
142139
with open(checkpoints + ".states", "rb") as f:
143-
states_dict = (
144-
pickle.load(f) if six.PY2 else pickle.load(f, encoding="latin1")
145-
)
140+
states_dict = pickle.load(f, encoding="latin1")
146141
best_model_dict = states_dict.get("best_model_dict", {})
147142
best_model_dict["acc"] = 0.0
148143
if "epoch" in states_dict:

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ classifiers = [
4141
dependencies = [
4242
"shapely",
4343
"scikit-image",
44-
"six",
4544
"pyclipper",
4645
"lmdb",
4746
"tqdm",

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
shapely
22
scikit-image
3-
six
43
pyclipper
54
lmdb
65
tqdm

test_tipc/supplementary/data.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,9 @@ def __init__(self, img_mode="RGB", channel_first=False, **kwargs):
4444

4545
def __call__(self, data):
4646
img = data["image"]
47-
if six.PY2:
48-
assert (
49-
type(img) is str and len(img) > 0
50-
), "invalid input 'img' in DecodeImage"
51-
else:
52-
assert (
53-
type(img) is bytes and len(img) > 0
54-
), "invalid input 'img' in DecodeImage"
47+
assert (
48+
type(img) is bytes and len(img) > 0
49+
), "invalid input 'img' in DecodeImage"
5550
img = np.frombuffer(img, dtype="uint8")
5651
img = cv2.imdecode(img, 1)
5752
if img is None:

test_tipc/supplementary/utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ def load_model(config, model, optimizer=None):
132132

133133
if os.path.exists(checkpoints + ".states"):
134134
with open(checkpoints + ".states", "rb") as f:
135-
states_dict = (
136-
pickle.load(f) if six.PY2 else pickle.load(f, encoding="latin1")
137-
)
135+
states_dict = pickle.load(f, encoding="latin1")
138136
best_model_dict = states_dict.get("best_model_dict", {})
139137
if "epoch" in states_dict:
140138
best_model_dict["start_epoch"] = states_dict["epoch"] + 1

0 commit comments

Comments
 (0)