---
title: "Real-time visualization of Computer Vision model training with DVC and Iterative Studio"
description: "Watching a computer vision model train in real time: DVCLive logs a ResNet-18 pool-segmentation run, and Iterative Studio shows it live to the whole team."
url: "https://mvshmakov.dev/writing/dvclive-metrics-studio/"
authors: ["Maxim Shmakov","Alex Kim","David de la Iglesia"]
published: "2023-02-13"
original: "https://dvc.org/blog/dvclive-metrics-studio"
---

# Real-time visualization of Computer Vision model training with DVC and Iterative Studio

By [Maxim Shmakov](https://mvshmakov.dev/), [Alex Kim](https://www.linkedin.com/in/alex000kim/) and [David de la Iglesia](https://github.com/daavoo) · 13 February 2023 · First published on the DVC blog

![The DVC owl next to a laptop with an Iterative Studio project open, its loss plots and satellite tiles with the pools found](https://mvshmakov.dev/_astro/cover.kgm3vLix_2gmPkR.jpg)

Computer vision is a complex field requiring much experimentation and trial and
error to achieve optimal results. However, managing and tracking the progress of
these experiments has not been easy. You can't see it once you've sent it to the
server for training. Keeping an eye on its progress over (often) days makes it
possible to miss something. This makes it difficult to effectively manage your
time and reduce unnecessary resource use. Moreover, a team working on the same
project needs to be able to easily share their results with colleagues. This can
be challenging with existing (or non-existent) tooling.

That's where DVCLive and Iterative Studio come in. These tools offer live
experiment tracking and efficient result sharing, making it easy to optimize
your experimentation process and streamline the workflow with your team.

[Video: Experiment plots updating in real time in Iterative Studio](https://mvshmakov.dev/writing/dvclive-metrics-studio/live-plots.mp4)
_See experiment results in real-time in Iterative Studio_

## The tools at work

[DVCLive](https://doc.dvc.org/dvclive) is a Python library connected to DVC that
provides a real-time experiment logger that allows machine learning engineers to
track the metrics and parameters of their experiments. It is beneficial for
long-running experiments, which can take hours or even days to complete.

[Iterative Studio](https://studio.datachain.ai/) is a
[SaaS](https://en.wikipedia.org/wiki/Software_as_a_service) platform that
displays logged experiments with their metrics, parameters, and plots all tied
together and tracked using DVC and Git under the hood. It allows for rich,
visual, real-time tracking and sharing of the results, making it easy to
collaborate with others and be production-ready efficiently.

[Video: Experiment metrics updating in real time in an Iterative Studio project table](https://mvshmakov.dev/writing/dvclive-metrics-studio/live-metrics.mp4)
_Real-time, nested experiment tracking in Iterative Studio_

## Use case: Identifying and segmenting pools from satellite imagery

In this computer vision project (see its
[example repository](https://github.com/treeverse/example-get-started-experiments)), we embark
on an exciting journey to uncover swimming pools, often obscured from
street-level views, right in the middle of our neighborhoods and cities. Using
[ResNet-18](https://www.mathworks.com/help/deeplearning/ref/resnet18.html) and
[Fast.ai](https://www.fast.ai/), we will be able to accurately identify and
segment pools from satellite images.

![Satellite images of a neighborhood with their pool and water tank annotations](https://mvshmakov.dev/_astro/bh-pools-dataset._oaw1cPm_1bvwWA.webp)
_Images and ground truth segmentation of BH-Pools Dataset
([Source link](https://patreo.dcc.ufmg.br/about-us/))_

> It's worth noting that the experiment in this example is beyond a toy project
> by design. It may take around one hour to run on an ordinary laptop, and the
> time may vary depending on the specific configuration and settings. However,
> you can use a GPU to speed up the process.

## Dataset, Methods & Tools

We will use a modified version of the
[BH-Pools dataset](https://patreo.dcc.ufmg.br/about-us/),
which consists of high-resolution 4K images of various neighborhoods in the city
of Belo Horizonte, Brazil. These images were captured through Google Earth Pro
and come pre-annotated with swimming pools and water tanks. For this project, we
will focus on just the swimming pools.

We have made the dataset more manageable with some pre-processing to crop the
images into smaller tiles of 1024x1024 pixels.

When using DVCLive in Iterative Studio, we will be able to see the progress of
our experiments. Let’s get started!

## Getting Set up

Follow the initial setup instructions in the
[README](https://github.com/treeverse/example-get-started-experiments). Next, we
need to run `dvc pull` in our root directory to fetch the dataset from our
remote. This command retrieves the data from the remote storage and makes it
available locally for our experiments. Once the download is complete, we will
create a data loader using the label function with `SegmentationDataLoaders`
from the `fastai` library. This data loader allows us to easily load and
preprocess the images (e.g. resizing the images to the desired resolution). You
can dig deeper into the code in
[the training script](https://github.com/treeverse/example-get-started-experiments/blob/main/src/train.py).

![Tiles of satellite images with swimming pools highlighted](https://mvshmakov.dev/_astro/swimming-pools-dataset.IqB8Oy_l_ZveLfP.webp)
_Sample of Belo Horizonte Pools Dataset from `data_loader`
([Source link](https://patreo.dcc.ufmg.br/about-us/))_

After creating the data loader and resizing the images, we train a ResNet-18
model with unet_learner with varying hyperparameters and utilizing the
DVCLiveCallback. The DVCLiveCallback is a built-in logger provided by DVCLive
that allows us to track the intermediate results of the training process, such
as the loss and accuracy of the model, in real-time. By logging these metrics,
we can easily monitor the progress of our model and make adjustments as needed
to optimize the training process and improve the performance of the model.

```python
learn = unet_learner(
    data_loader, arch=getattr(models, params.train.arch), metrics=DiceMulti
)

learn.fine_tune(
    **params.train.fine_tune_args,
    cbs=[DVCLiveCallback(dir="results/train", report="md", dvcyaml=False)],
)
```

Additionally, we can also use Studio to analyze and visualize the results of our
experiments, making it easy to share and collaborate with others.
[By providing the STUDIO_TOKEN](https://www.datachain.ai/docs/studio),
DVCLive will automatically post the results of the experiment to Studio. To do
this, first, let’s obtain an individual token from the user profile page in
Studio.

![The access token section of the Iterative Studio profile page](https://mvshmakov.dev/_astro/studio-access-token.Eh0Pk9uZ_Zm93CK.webp)
_Generating Studio Access Token in the Iterative Studio Profile page
([Source link](https://studio.datachain.ai))_

By providing this token as an environment variable, we can access the results of
our experiments in an
[Iterative Studio project](https://www.datachain.ai/docs/studio). The project
lets you compare them with previous experiments, helps you find insights to
improve our model and share it with others.

![An Iterative Studio project table comparing experiments and their metrics](https://mvshmakov.dev/_astro/studio-compare.B2KxGLMc_iyepY.webp)
_Compare with previous experiments in Iterative Studio
([Source link](https://studio.datachain.ai))_

To export the token run the command below with the token obtained from your
Studio profile:

```bash
export STUDIO_TOKEN=<your-token>
```

Running an experiment locally using DVC will now automatically live-update the
Studio project(s) associated with your git remote (the one named "origin")

You may want to change the parameters and run the experiment again.

```bash
dvc exp run -S train.fine_tune_args.epochs=16 -S train.img_size=512
```

[Video: A new experiment's metrics and plots updating live in Iterative Studio](https://mvshmakov.dev/writing/dvclive-metrics-studio/exp-run.mp4)
_Real-time Experiment tracking in Iterative Studio
([Source link](https://studio.datachain.ai))_

As you can see, the change to the epochs and image size brought improvement to
the metrics.

It's safe to say that if you provide the model with a satellite image of any
neighborhood, it will pretty accurately identify all swimming pools in that
image! And by using DVCLive and Studio, we were able to track and efficiently
control the model training process, without squandering expensive training
resources on unfruitful training runs.

## Conclusion

Our work has produced a model which is able to accurately identify and segment
swimming pools from satellite images! With the help of DVCLive and Iterative
Studio, we've been able to visualize results in real-time to make
resource-saving decisions. And finally, this work is readily visible for the
entire team to review!

We’d like to express our gratitude to the creators of the incredible
[BH-Pools dataset](https://patreo.dcc.ufmg.br/about-us/), without which there
would have been less fun and less impressive results!

You can give Iterative Studio a try by
[signing up for it](https://studio.datachain.ai). Try out
the [repo](https://github.com/treeverse/example-get-started-experiments)
or [colab notebook](https://colab.research.google.com/drive/1NTivljRYiySMJn-SHeWQSycBmSOVUbvA)
for this project and let us know what you think
on the [DVC forum](https://discuss.dvc.org/t/track-computer-vision-experiments-in-real-time-with-dvclive-in-iterative-studio/1478)!

---

First published on the DVC blog on 13 February 2023, at https://dvc.org/blog/dvclive-metrics-studio, which is no longer online. The [original text](https://github.com/treeverse/dvc.org/blob/7dfc12ba/content/blogs/2023-02-13-dvclive-metrics-studio.md) is on GitHub, under the [Apache License 2.0](https://github.com/treeverse/dvc.org/blob/7dfc12ba/LICENSE).

Changes in this copy: Links updated where their targets moved (the DVC docs, the example repository, the Studio docs and the dataset page), links that read "here" named after their targets, and the closing promotion of other posts and community channels removed.
