Exercise 3 step 2: Executing the segmentation script locally

This exercise can be done either on your own machine or on ehproduction02.

Unpack and activate Conda environment

Use a fresh shell to start this step, i.e. one without an activated conda environment. We want to use our relocatable conda enviroment either created in the previous step, or a prepared one provided as material on ehproduction02 under /home/martin/training/orthophotos/solution/conda-segmentation.tar.gz.

We would like to test our packed conda environment because this is the one we are going to deploy. If you packaged the environment yourself you will have the unpacked environment in the conda-segmentation subdirectory of your working directory already. To test the packaged environment, you need to remove (or rename) the environment first so that you can unpack the packed environment without conflict.

If you can use your own packed environment, use

# move the existing unpacked environment
mv conda-segmentation conda-segmentation-orig
# unpack the packaged environment to test it
mkdir conda-segmentation
cd conda-segmentation
tar xf ../conda-segmentation.tar.gz
cd ..

In the case that you are working on your local machine and want to use the prepared environment, you need to copy it to your machine first and adjust the path to conda-segmentation.tar.gz accordingly. Then unpack the environment:

mkdir conda-segmentation
cd conda-segmentation
tar xf /home/martin/training/orthophotos/solution/conda-segmentation.tar.gz
cd ..

To activate this environment

. conda-segmentation/bin/activate

When your environment is active, you should see that your shell prompt changes to show the name of the environment.

Local installation

In addition to the dependencies provided in the Conda environment we need the software to run orthophoto segmentation. Sander had provided it as a small directory tree with a Python script main.py, the trained model, an example input, and a configuration. Copy this directory tree to your directory.

You can skip this, if you already copied the directory in the last step.

If you are working on ehproduction02:

# in your working directory on ehproduction02
cp -r /home/martin/training/orthophotos/sander-script .
ls -l sander-script

If you are working on your local computer:

# in your working directory on your local computer
scp -r ehproduction02:/home/martin/training/orthophotos/sander-script .
ls -l sander-script

Local execution test

Change into the directory and run the script with

cd sander-script
cat config.yaml
python main.py --conf config.yaml

The file config.yaml contains configuration options such the path to the input and a file name for the output file. The input file is provided under data/588541/588541.tif

Hint: You may want to stop execution of the Python script once you have convinced yourself that it is working, as it may take some time to complete. If you see a progress bar appearing, the script is likely running correctly. You can interrupt the program by holding down Ctrl and pressing the c key.

If you want to have a look at the output without waiting for the script to complete, an example output can be found on ehproduction02 at /home/martin/training/orthophotos/solution/588541_segments.tif.

Next steps

Now that the Python script successfully runs, we can move on to creating a software package for deployment on Calvalus.