Skip to content

Running the step

Goal

Run the command line tool in a Python virtual environment.

Dependencies

This step depends on the execution of the stage-and-cog.cwl workflow that stages a Sentinel-2 Level-1C from the CDSE and converts/resamples its assets to COG.

Lab

This step has a dedicated lab available at /workspace/inference-eoap/practice-labs/Application steps/02 - Inference.ipynb

Step 1 - Configure the workspace

The results produced will be available in the local folder /workspace/inference-eoap/runs

terminal
1
2
3
4
export WORKSPACE=/workspace/inference-eoap
export RUNTIME=${WORKSPACE}/runs
mkdir -p ${RUNTIME}
cd ${RUNTIME}

Step 2 - Create the Python virtual environment

The required Python modules are installed using pip:

terminal
1
2
3
python3 -m venv env_inference
source env_inference/bin/activate
pip install --no-cache-dir pystac==1.9.0 click loguru requests numpy rasterio onnx onnxruntime rio-stac

Step 3 - Run the inference

The command line tool is invoked with:

terminal
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
WORKSPACE=/workspace/inference-eoap
RUNTIME=${WORKSPACE}/runs
mkdir -p ${RUNTIME}
cd ${RUNTIME}

# check if the results.json file exists
if [ ! -f ${WORKSPACE}/runs/results.json ]; then
    echo "results.json file not found, run the stage-and-cog.cwl workflow first."
    exit 1
fi

python \
    ${WORKSPACE}/tile-based-classification/command-line-tools/inference/app.py \
    --input-item $( cat ${WORKSPACE}/runs/results.json | jq -r .stac_catalog.path )

Step 4 - Clean-up

The Python virtual environment is no longer needed.

terminal
1
2
deactivate
rm -fr env_inference

Expected outcome

The folder /workspace/inference-eoap/runs contains:

runs
├── S2A_T33TVM_20240125T100359_L1C-classification
│   ├── S2A_T33TVM_20240125T100359_L1C-classification.json
│   └── classification.tif
├── catalog.json
├── results.json
└── ydmns4od
    ├── S2A_T33TVM_20240125T100359_L1C
    │   ├── S2A_T33TVM_20240125T100359_L1C.json
    │   ├── blue.tif
    │   ├── cirrus.tif
    │   ├── coastal.tif
    │   ├── green.tif
    │   ├── nir.tif
    │   ├── nir08.tif
    │   ├── nir09.tif
    │   ├── red.tif
    │   ├── rededge1.tif
    │   ├── rededge2.tif
    │   ├── rededge3.tif
    │   ├── swir16.tif
    │   └── swir22.tif
    └── catalog.json

3 directories, 19 files