Skip to content

Commit 9111635

Browse files
committed
Change from skimage.transform.resize to cv2.resize
To make the process of cropping and resizing images go faster, switch from the resize function in skimage.transform to the resize function in cv2.
1 parent b9402d1 commit 9111635

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The performance of each model variant using the pre-trained weights converted fr
7979
### Requirements
8080

8181
* `keras >= 2.2.0` + `tensorflow`
82-
* `scikit-image`
82+
* `opencv >= 3.4.2`
8383

8484
### Installing from the source
8585

efficientnet/preprocessing.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
# limitations under the License.
1414
# ==============================================================================
1515
import numpy as np
16-
from skimage.transform import resize
16+
import cv2
1717

1818
MEAN_RGB = [0.485 * 255, 0.456 * 255, 0.406 * 255]
1919
STDDEV_RGB = [0.229 * 255, 0.224 * 255, 0.225 * 255]
2020

2121
MAP_INTERPOLATION_TO_ORDER = {
22-
"nearest": 0,
23-
"bilinear": 1,
24-
"biquadratic": 2,
25-
"bicubic": 3,
22+
"nearest": cv2.INTER_NEAREST,
23+
"bilinear": cv2.INTER_LINEAR,
24+
"bicubic": cv2.INTER_CUBIC,
25+
"laconzos": cv2.INTER_LANCZOS4
2626
}
2727

2828

@@ -59,11 +59,10 @@ def center_crop_and_resize(image, image_size, crop_padding=32, interpolation="bi
5959
offset_w : unpadded_center_crop_size_pre_scaling[1] + offset_w,
6060
]
6161

62-
resized_image = resize(
62+
resized_image = cv2.resize(
6363
image_crop,
64-
(out_h, out_w),
65-
order=MAP_INTERPOLATION_TO_ORDER[interpolation],
66-
preserve_range=True,
64+
(out_w, out_h),
65+
interpolation=MAP_INTERPOLATION_TO_ORDER[interpolation] if inv_scale < 1 else cv2.INTER_AREA
6766
)
6867

6968
return resized_image

0 commit comments

Comments
 (0)