Skip to content

Commit 3daf692

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 356f107 commit 3daf692

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
@@ -92,7 +92,7 @@ The performance of each model variant using the pre-trained weights converted fr
9292

9393
* `Keras >= 2.2.0` / `TensorFlow >= 1.12.0`
9494
* `keras_applications >= 1.0.7`
95-
* `scikit-image`
95+
* `opencv >= 3.4.2`
9696

9797
### Installing from the source
9898

efficientnet/preprocessing.py

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

1818
MAP_INTERPOLATION_TO_ORDER = {
19-
"nearest": 0,
20-
"bilinear": 1,
21-
"biquadratic": 2,
22-
"bicubic": 3,
19+
"nearest": cv2.INTER_NEAREST,
20+
"bilinear": cv2.INTER_LINEAR,
21+
"bicubic": cv2.INTER_CUBIC,
22+
"laconzos": cv2.INTER_LANCZOS4
2323
}
2424

2525

@@ -55,11 +55,10 @@ def center_crop_and_resize(image, image_size, crop_padding=32, interpolation="bi
5555
offset_h : unpadded_center_crop_size_pre_scaling[0] + offset_h,
5656
offset_w : unpadded_center_crop_size_pre_scaling[1] + offset_w,
5757
]
58-
resized_image = resize(
58+
resized_image = cv2.resize(
5959
image_crop,
60-
(out_h, out_w),
61-
order=MAP_INTERPOLATION_TO_ORDER[interpolation],
62-
preserve_range=True,
60+
(out_w, out_h),
61+
interpolation=MAP_INTERPOLATION_TO_ORDER[interpolation] if inv_scale < 1 else cv2.INTER_AREA
6362
)
6463

6564
return resized_image

0 commit comments

Comments
 (0)