CS 5043: HW7: Conditional Diffusion Networks

DRAFT

Assignment notes:

The Problem

We will generate synthetic satellite images that are conditioned on semantic image labels. Here, we will use a Markov chain of models that slowly introduce noise into a real image (this is how we will generate our training data), and a reverse set of models that will start from a completely random image and slowly remove noise until a meaningful satellite image is revealed.

Your model will take as input:

And produce as output a guess at the noise that must be removed from the input noised image in order to make it less noisy.

Once your model is trained, we will use it to generate synthetic images by:

The Generator

We have provided a new version of the chesapeake_loader4.py file with a new TF Dataset creator called create_diffusion_dataset(). An example of its use is given in the hw7_examples.ipynb file. Following, Algorithm 18.1 in the book, this generator produces batches of examples. For each example, the generator randomly selects a time step in the noising process to sample from and produces a single 2-tuple of the form:

The Model

You should start from the semantic labeling U-net that you have already developed in HW 4. The differences are:

Provided Tools

diffusion_tools.py chesapeake_loader4.py

Key function:

       
    ds_train, ds_valid = create_diffusion_dataset(
        base_dir=args.dataset,
        patch_size=args.image_size[0],
        fold=args.rotation,
        filt=args.train_filt,
        cache_dir=args.cache,
        repeat=args.repeat,
        shuffle=args.shuffle,
        batch_size=args.batch,
        prefetch=args.prefetch,
        num_parallel_calls=args.num_parallel_calls,
        alpha=alpha,
        time_sampling_exponent=args.time_sampling_exponent)

Training Process

You can train your model using a conventional model.fit() process with early stopping (no meta models!).

Inference Process

I suggest doing this in a notebook. To reload a saved model, you will need:
model = keras.models.load_model(fname + '_model.h5', custom_objects={'PositionEncoder': PositionEncoder,
                                                                     'ExpandDims': keras.src.ops.numpy.ExpandDims,
                                                                     'Tile': keras.src.ops.numpy.Tile,
                                                                     'mse': 'mse'})

Experiments

We are only working to get a single model running for this assignment. Once you have completed your main experiment, produce the following:
  1. Figure 0: Model architectures from plot_model()

  2. Figures 1a,b: Show training and validation set MSE (or MAE) as a function of epoch.

  3. Figure 2: Show 2-3 examples of the model producing a new image from noise. Show each time step (or maybe every other time step).

  4. Figure 3: Show a gallery of final images.


What to Hand In

Turn in a single zip file that contains:

Grading

Hints

Frequently Asked Questions


andrewhfagg -- gmail.com

Last modified: Tue Apr 29 13:27:01 2025