File size: 931 Bytes
17124c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os

os.environ.setdefault("TF_CPP_MIN_LOG_LEVEL", "2")
os.environ.setdefault("TF_NUM_INTRAOP_THREADS", "6")
os.environ.setdefault("TF_NUM_INTEROP_THREADS", "2")
import numpy as np
from PIL import Image, ImageOps

CLASSES = ["Forest", "River", "Residential", "Agriculture", "Industrial"]
SOURCE_CLASSES = ["Forest", "River", "Residential", "AnnualCrop", "Industrial"]
SIZE = 64


def preprocess(image):
    """Return RGB float32 pixels in [0,255]; the model contains normalization."""
    image = ImageOps.exif_transpose(image).convert("RGB")
    return np.asarray(
        image.resize((SIZE, SIZE), Image.Resampling.BILINEAR), dtype=np.float32
    )


def configure(seed=42):
    import tensorflow as tf

    tf.keras.utils.set_random_seed(seed)
    tf.config.experimental.enable_op_determinism()
    return {
        "devices": [str(d) for d in tf.config.list_physical_devices()],
        "deterministic_ops": True,
    }