Skip to content

Commit

Permalink
Updated african-wildlife example to a setup guide instead of full exa…
Browse files Browse the repository at this point in the history
…mple
  • Loading branch information
David Hovstadius committed Oct 29, 2024
1 parent 8a597f3 commit 7c78aed
Showing 1 changed file with 21 additions and 55 deletions.
76 changes: 21 additions & 55 deletions examples/african-wildlife/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

**Note: If you are new to FEDn, we recommend that you start with the MNIST-Pytorch example instead: https://github.com/scaleoutsystems/fedn/examples/mnist-pytorch**

# African Wildlife Example

This is an example FEDn project that trains the Ultralytics YOLOv8n model to classify buffalos, elephants, rhinos and zebras. See a few examples below,
Expand All @@ -14,70 +11,39 @@ This is an example FEDn project that trains the Ultralytics YOLOv8n model to cla
<img src="figs/zebra.jpg" width=30% height=30%>


## Step 1:. Downloading the data

## How to run the example

To run the example, follow the steps below. For a more detailed explanation, follow the Quickstart Tutorial: https://fedn.readthedocs.io/en/stable/quickstart.html



### 1. Prerequisites

- `Python >=3.8, <=3.12` <https://www.python.org/downloads>
- `A project in FEDn Studio` <https://fedn.scaleoutsystems.com/signup>


### 2. Install FEDn and clone GitHub repo

Install fedn:

```
pip install fedn
```

Clone this repository, then locate into this directory:

```
git clone https://github.com/scaleoutsystems/fedn-ultralytics-tutorial.git
cd fedn-ultralytics-tutorial/examples/african-wildlife
```
Download the dataset from the following link and extract it to the `datasets` directory:
<https://github.com/ultralytics/assets/releases/download/v0.0.0/african-wildlife.zip>

### 3. The dataset

1. Create a directory inside the african-wildlife folder
```
mkdir datasets
```
2. Download the dataset from https://github.com/ultralytics/assets/releases/download/v0.0.0/african-wildlife.zip
3. Unzip and move the folder to the "datasets" directory you just created
## Step 2: Partitioning the data

Then run the script partition_data.py to split the dataset into random partitions to distribute to the clients.
To partition the data for each client, run the following command:

```bash
python3 partition_data.py <number of partitions>
python3 partition_data.py african-wildlife <num_splits>
```
Replace `<num_splits>` with the number of clients you want to partition the data for.

Note: Each client needs to call their dataset partition the same, so rename the datasets after distributing them.
This generates the dataset partitions in the 'datasets' directory. These partitions needs to be distributed to the respective clients and renamed to 'african-wildlife' instead of 'african-wildlife_split_X.

### 4. Creating the compute package and seed model
## Step 3: Setting up the global_config.yaml

Create the compute package:
Inside the 'client' folder configure the 'global_config.yaml' in the following way:

```
fedn package create --path client
```

This creates a file 'package.tgz' in the project folder.
```bash
# Configuration for YOLOv8 Model and Dataset Paths
# Adjust settings here to define model size, class details, and dataset paths

Next, generate the seed model:
model_size: nano # Options: nano, small, medium, large, extra-large
num_classes: 4 # Number of classes
class_names: ['Buffalo', 'Elephant', 'Rhino','Zebra'] # A list of class names

train: african-wildlife/train/images # Configure paths (usually not needed to be configured)
val: african-wildlife/valid/images
test: african-wildlife/test/images
```
fedn run build --path client
```

This will create a model file 'seed.npz' in the root of the project. This step will take a few minutes, depending on hardware and internet connection (builds a virtualenv).

### 5. Running the project on FEDn

To learn how to set up your FEDn Studio project and connect clients, take the quickstart tutorial: https://fedn.readthedocs.io/en/stable/quickstart.html. When activating the first client, the dataset inside your datasets directory and the data.yaml file will be moved to dedicated client folders to mimic the behavior of a distributed setup where the data sits locally at the client.

## Step 4: Return to the root guide and follow the instructions from there
Now your dataset is ready and you have configured the global settings for the YOLOv8 model. Return to the root guide and follow the instructions from there to continue with the federated learning process.

0 comments on commit 7c78aed

Please sign in to comment.