# Domain Adaptation

Domain Adaptation can make synthetic data useful by bridging the domain gap between a digital twin camera and your sensor. Rendered.ai users train CycleGAN models for pixel level domain adaptation from raw synthetic data to domain adapted sythetic data. This tutorial will walk through the steps of uploading a GAN model to a workspace, and generating domain adapted datasets.

Read more about CycleGAN

[Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks](https://junyanz.github.io/CycleGAN/)

### Uploading a GAN Model <a href="#uploading-a-gan-model" id="uploading-a-gan-model"></a>

Rendered.ai supports PyTorch CycleGAN models for domain adaptation. Many of the models shown in the CycleGAN landing page linked above are available for download. For demonstration purposes, we will use the apple-to-orange pre-trained model available here:

[Index of /cyclegan/pretrained\_models](http://efrosgans.eecs.berkeley.edu/cyclegan/pretrained_models/)

To use the `apple2orange.pth` model, it must be added to your organization, and then associated with a workspace.

#### Add a Model to an Organization <a href="#add-a-model-to-an-organization" id="add-a-model-to-an-organization"></a>

Navigate to your organization’s GAN Models management space.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FCDLb9qCEXPDg3YacvggC%2FNew%20GAN%20Model%20Button.png?alt=media&#x26;token=7075943c-0565-4bd0-9116-38c879bc89e2" alt=""><figcaption><p>New GAN Model Button</p></figcaption></figure>

Under your organization (1), find the GAN Model section (2), and click the `+ New GAN Model` button (3).

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FYQvTEA6TdMzzxOm7qcDI%2FNew%20GAN%20Mode%20Dialog.png?alt=media&#x26;token=a0a9cc91-5720-400b-af63-5e82f9920e5b" alt=""><figcaption><p>New GAN Model Dialog</p></figcaption></figure>

In the new GAN model upload dialog, give the model a name and set the inference flags. The pre-trained CycleGAN models were trained with the `--no_dropout` flag, so it is required for inference.

#### Add a Model to a Workspace <a href="#add-a-model-to-a-workspace" id="add-a-model-to-a-workspace"></a>

Each workspace has various resources, such as channels, annotation maps, and GAN models. To manage these resources, navagate to the organization’s workspaces.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FyijrSvpXKb8BLcG86S89%2FWorkspace%20Resources.png?alt=media&#x26;token=c5be8347-e3c5-4d1d-96ca-fd76f85b9f26" alt=""><figcaption></figcaption></figure>

From your workspaces manager, select list mode, select the three vertical dots next to the workspace you want to edit, and select the `Resources` option.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FI4cAaiZmzYokdKK0lazo%2FGAN%20Model%20Manager%20for%20Content%20Workspace.png?alt=media&#x26;token=60010457-839f-4999-b18e-bb21bd8fd101" alt=""><figcaption><p>GAN Model Manager for Content Workspace</p></figcaption></figure>

There are two models that come with the content workspace. Add the new model from the `Excluded` list to the `Included` list.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FwFwsNOkV1rOHo0nr84gd%2FApple%20to%20Orange%20Transfiguration%20Model%20Included.png?alt=media&#x26;token=a1a60b11-f53c-46e0-9e8e-1e829365be2b" alt=""><figcaption><p>Apple to Orange Transfiguration Model Included</p></figcaption></figure>

Once the new model is associated with the Example workspace, click `Save`.

#### Create a Domain Adapted Dataset <a href="#create-a-domain-adapted-dataset" id="create-a-domain-adapted-dataset"></a>

The Content workspace comes pre-loaded with some datasets, and the one named `Custom Objects` is made up of images containing apples. To use the Apple to Orange Transfiguration CycleGAN model, create a GAN dataset based on `Custom Objects`.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2F0p488ms1Td8oOKicXK58%2FContent%20Workspace%20Datasets.png?alt=media&#x26;token=3908f88d-2b76-48aa-a4cb-3073010343f2" alt=""><figcaption><p>Content Workspace Dataset</p></figcaption></figure>

From the Datasets tab in the Content workspace, select the `Custom Objects` dataset, and open the wizard for creating a GAN dataset.

<figure><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FIM12J956luoeiabheYim%2FCreate%20GAN%20Dataset%20Configuration.png?alt=media&#x26;token=2452c070-319b-45c7-92e6-a46507d81213" alt=""><figcaption><p>Create GAN Dataset Configuration</p></figcaption></figure>

Give the new dataset a name, select the domain adaptation model, and, optionally, give it a description. When the job is complete take a look at the results.

| <p><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2F9mbNzl3ZlXv5N6W32r1g%2F6071cb71-5adc-4f8c-ab53-892210f19258.png?alt=media&#x26;token=da0fba22-18a0-4bd3-ae85-f4ecf49d899d" alt="" data-size="original"></p><p>Raw Synthetic Data Image</p><p> </p> | <p><img src="https://3091318601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbPMRyh7BHNPMVqv2031A%2Fuploads%2FE0AAmeeiIuGKrxJ5q0Xt%2F481bb094-0e12-489b-aafe-c2568b6f5be5.png?alt=media&#x26;token=2f5ac314-2990-442f-833d-30a71b74f570" alt="" data-size="original"></p><p>Domain Adapted Image</p><p></p> |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

Congratulations! This model can be used in other workspaces or on other datasets. To generate GAN datasets in your ML pipeline, please take a look at our SDK.

SDK Documentation: [https://sdk.rendered.ai](https://sdk.rendered.ai/)

SDK Examples: [https://github.com/Rendered-ai/resources](https://github.com/Rendered-ai/resources)
