<jupyter_start><jupyter_text>Jelapang PadiEfficientNet-Unet trained on https://huggingface.co/datasets/malay-huggingface/jelapang-padi  CheckpointsAll checkpoints can get at https://huggingface.co/malay-huggingface/jelapang-padi  Preparation scriptAll scripts and notebooks can get at https://github.com/malaysia-ai/projects/tree/master/malaysia_ai_projects/jelapang_padi  Install necessary requirements```bashpip3 install tensorflow>=1.15 malaya-boilerplate==0.0.15 skimage```<jupyter_code>from malaysia_ai_projects import jelapang_padi<jupyter_output><empty_output><jupyter_text>List available models<jupyter_code>jelapang_padi.available_model()<jupyter_output><empty_output><jupyter_text>Load model```pythondef load(model: str = 'efficientnet-b2', **kwargs):    """    Load Jelapang Padi model.    Parameters    ----------    model : str, optional (default='efficientnet-b2')        Model architecture supported. Allowed values:        * ``'efficientnet-b4'`` - EfficientNet B4 + Unet.        * ``'efficientnet-b4-quantized'`` - EfficientNet B4 + Unet with dynamic quantized.        * ``'efficientnet-b2'`` - EfficientNet B2 + Unet.        * ``'efficientnet-b2-quantized'`` - EfficientNet B2 + Unet with dynamic quantized.    Returns    -------    result : malaysia_ai_projects.jelapang_padi.Model class    """```<jupyter_code>model = jelapang_padi.load()<jupyter_output><empty_output><jupyter_text>Predict```pythondef predict(self, inputs: List[np.array]):    """    Parameters    ----------    input: List[np.array]        List of np.array, should be size [H, W, 3], `H` and `W` can be dynamic.    Returns    -------    result: List[np.array]    """```<jupyter_code>from glob import glob

files = glob('example/jelapang-padi/*.png')
files
from skimage.io import imread

images = []
for f in files:
    images.append(imread(f))
outputs = model.predict(images)
len(outputs)
import matplotlib.pyplot as plt
plt.figure(figsize = (10, 5))
plt.subplot(1,2,1)
plt.imshow(images[0])
plt.subplot(1,2,2)
plt.imshow(outputs[0][:,:,0])
plt.figure(figsize = (10, 5))
plt.subplot(1,2,1)
plt.imshow(images[1])
plt.subplot(1,2,2)
plt.imshow(outputs[1][:,:,0])
images[0].shape, outputs[0][:,:,0].shape<jupyter_output><empty_output><jupyter_text>Download satellite image using Mapbox<jupyter_code># https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Tile_numbers_to_lon..2Flat.

import math
import requests
import shutil

def deg2num(lat_deg, lon_deg, zoom):
    lat_rad = math.radians(lat_deg)
    n = 2.0 ** zoom
    xtile = int((lon_deg + 180.0) / 360.0 * n)
    ytile = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
    return (xtile, ytile)

def num2deg(xtile, ytile, zoom):
    n = 2.0 ** zoom
    lon_deg = xtile / n * 360.0 - 180.0
    lat_rad = math.atan(math.sinh(math.pi * (1 - 2 * ytile / n)))
    lat_deg = math.degrees(lat_rad)
    return (lat_deg, lon_deg)

def download_img(lat, lon, zoom = 14, output_name = 'img.png'):
    x, y = deg2num(lat, lon, zoom)
    url = f'https://api.mapbox.com/styles/v1/mapbox/satellite-v9/tiles/{zoom}/{x}/{y}@2x?title=true&logo=false&access_token=<KEY>'
    response = requests.get(url, stream=True)
    with open(output_name, 'wb') as out_file:
        shutil.copyfileobj(response.raw, out_file)
output_name = 'example/jelapang-padi/test.png'
download_img(lat = 5.671607, lon = 100.463231, zoom = 15, output_name = output_name)
image = imread(output_name)
plt.imshow(image)
outputs = model.predict([image])
plt.figure(figsize = (10, 5))
plt.subplot(1,2,1)
plt.imshow(image)
plt.subplot(1,2,2)
plt.imshow(outputs[0][:,:,0])<jupyter_output><empty_output><jupyter_text>Calculate area of segmentation in km^2  pixel to meter ratiohttps://wiki.openstreetmap.org/wiki/Zoom_levels,Stile = (C ∙ cos(latitude) / (2 ^ zoomlevel)) / size imageC = 40075016.686malaysia latitude = 3.140853zoomlevel = 15I just take center of malaysia latitude, to get accurate result, take the actual latitude from the satellite image.<jupyter_code>import math
import numpy as np

C = 40075016.686
malaysia_lat = 3.140853
per_pixel = np.abs(C * np.cos(malaysia_lat) / (2**15)) / 1024
per_pixel<jupyter_output><empty_output><jupyter_text>So we know 1 pixel = 1.19m,pixel = 1.19mpixel^2 = 1.19m * 1.19mpixel^2 = 1.4161m^2pixel^2 / 1.4161 = m^2Now, get total segmentation in term of pixels,<jupyter_code>total_pixel = (outputs[0][:,:,0] > 0).sum()
total_pixel
km_square = (total_pixel / (per_pixel * per_pixel)) / 1e6
km_square<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15165031222123104, 'fraction_numerical': 0.0423728813559322, 'mean_word_length': 4.677215189873418, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 32, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '120780', 'license': 'MIT', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1685, 'n_words': 326, 'path': 'example/jelapang-padi/load-jelapang-padi.ipynb', 'repo_name': 'malaysia-ai/projects', 'size': '4567'}