Training the MagNet has two steps:
- Make the virtual environment with requirements.
- Activate the environment. For example:
cd <path to the directory>/MagNet-main/
source <env name>/bin/activate
- Modify the config file at
<path to the directory/MagNet-main/backbone/experiments/deepglobe_river>
- Run the script
# To train without Stochastic Weight Averaging:
python train.py --cfg experiments/deepglobe_river/hairs_config_seed4.yaml --seed 4
# To use Stochastic Weight Averaging:
python train_swa.py --cfg experiments/deepglobe_river/hairs_config_seed4.yaml --seed 4
modify the parameters of the <path to the directory/MagNet-main/scripts/deepglobe_river/train_magnet.sh
Modify the script MagNet-main/prediction_from_dir.py
. The parameters are similar to the original MagNet.
python prediction_from_dir.py --progressive_flag 1 \
--dataset deepglobe_river \
--scales 612-612,1224-1224,2448-2448 \
--crop_size 612 612 \
--input_size 508 508 \
--model fpn \
--pretrained <your path> \
--pretrained_refinemen <your path> \
--num_classes 6 \
--n_points 0.75 \
--n_patches -1 \
--smooth_kernel 11 \
--sub_batch_size 1 \
1.Make the environment by making a docker container or setting up a conda environment using the requirements. In case of using docker:
# move to the directory
cd <path to the directory>/Other_models/
# To build the docker container
docker build -t saeids/segmentation segmentation/
# To start the container
docker run --rm -it -v $-v $<path to workscape data>:/workspace/data -v $<path to source code>:/workspace/code -v <path to data>:/data -p <your port of choice>:8888 --gpus device=<your device of choice> saeids/tf_gpu_v1 /bin/bash
- Activate the environment. For example:
conda activate tf_gpu_env
- Install all the required libraries
# If using the docker:
sh ./workspace/code/Other_models/source/installation.sh
-
Modify the training script
Other_models/source/run_from_dir_pretrain.py
for pre-trained on grayscaled DeepGlobe, andOther_models/source/run_from_dir_with_args.py
for training from scratch. -
Train the model
cd <path to the directory>/Other_models/source
# train
python run_from_dir_pretrain.py
# or
python run_from_dir_pretrain.py
-
Modify the config file at
Other_models/source/configs/prediction_config.yaml
-
run the script
# make sure the directory is correct
cd <path to the directory>/Other_models/source
python run_predictions_costum.py
- Make sure to follow the inference and have the predictions for all the images
- Modify the paths at the script
Other_models/source/Nips_test_miou_magnet.py
- Run the script:
# make sure the directory is correct
cd <path to the directory>/Other_models/source
python Nips_test_miou_magnet.py
- Modify the paths at the script
Other_models/source/Nips_test_miou.py
- Run the script:
# make sure the directory is correct
cd <path to the directory>/Other_models/source
python Nips_test_miou.py
The weights of pre-trained models on grayscaled DeepGlobe can be found in pretrained weights.