Spaces:
Runtime error
Runtime error
Upload encoders/_preprocessing.py
Browse files- encoders/_preprocessing.py +23 -0
encoders/_preprocessing.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
|
3 |
+
|
4 |
+
def preprocess_input(
|
5 |
+
x, mean=None, std=None, input_space="RGB", input_range=None, **kwargs
|
6 |
+
):
|
7 |
+
|
8 |
+
if input_space == "BGR":
|
9 |
+
x = x[..., ::-1].copy()
|
10 |
+
|
11 |
+
if input_range is not None:
|
12 |
+
if x.max() > 1 and input_range[1] == 1:
|
13 |
+
x = x / 255.0
|
14 |
+
|
15 |
+
if mean is not None:
|
16 |
+
mean = np.array(mean)
|
17 |
+
x = x - mean
|
18 |
+
|
19 |
+
if std is not None:
|
20 |
+
std = np.array(std)
|
21 |
+
x = x / std
|
22 |
+
|
23 |
+
return x
|