2023-10-06 17:50:51 +00:00
|
|
|
[{"location":"references/#References","page":"References","title":"References","text":"","category":"section"},{"location":"references/","page":"References","title":"References","text":"","category":"page"},{"location":"references/","page":"References","title":"References","text":"*","category":"page"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"EditURL = \"../../../examples/beta_schedulers_comparison.jl\"","category":"page"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"This example compares the different beta schedules available in Diffusers.jl. Code related to the generation of the datasets and the plots is hidden.","category":"page"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"using Diffusers.Schedulers: DDPM, forward # hide\nusing Diffusers.BetaSchedules # hide\nusing ProgressMeter # hide\nusing LaTeXStrings # hide\nusing Random # hide\nusing Plots # hide\nusing Flux # hide\nusing MLDatasets # hide\n\nfunction normalize_zero_to_one(x) # hide\n x_min, x_max = extrema(x) # hide\n x_norm = (x .- x_min) ./ (x_max - x_min) # hide\n x_norm # hide\nend # hide\n\nfunction normalize_neg_one_to_one(x) # hide\n 2 * normalize_zero_to_one(x) .- 1 # hide\nend # hide\n\nnum_timesteps = 100 # hide\nbeta_schedules = [ # hide\n linear_beta_schedule, # hide\n scaled_linear_beta_schedule, # hide\n cosine_beta_schedule, # hide\n sigmoid_beta_schedule, # hide\n exponential_beta_schedule, # hide\n] # hide\nschedulers = [ # hide\n DDPM(collect(schedule(num_timesteps))) for schedule in beta_schedules # hide\n]; # hide\nnothing #hide","category":"page"},{"location":"generated/beta_schedulers_comparison/#Swiss-Roll","page":"Beta Schedules Comparison","title":"Swiss Roll","text":"","category":"section"},{"location":"generated/beta_schedulers_comparison/","page":"Beta Schedules Comparison","title":"Beta Schedules Comparison","text":"function make_spiral(n_samples::Integer=1000, t_min::Real=1.5π, t_max::Real=4.5π) # hide\n t = rand(typeof(t_min), n_samples) * (t_max - t_min) .+ t_min # hide\n\n x = t .* cos.(t) # hide\n y = t .* sin.(t) # hide\n\n permutedims([x y], (2, 1)) # hide\nend # hide\n\nn_points = 1000; # hide\ndataset = make_spiral(n_points, 1.5f0 * π, 4.5f0 * π); # hide\ndataset = normalize_neg_one_to_one(dataset); # hide\n\nnoise = randn(Float32, size(dataset)) # hide\nanim = @animate for t in cat(fill(0, 20), 1:num_timesteps, fill(num_timesteps, 20), dims=1) # hide\n plots = [] # hide\n for (i, (scheduler, beta_schedule)) in enumerate(zip(schedulers, beta_schedules)) # hide\n if t == 0 # hide\n scatter(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n legend=false, # hide\n ) # hide\n plot = scatter!(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n ) # hide\n title!(string(beta_schedule)) # hide\n xlims!(-3, 3) # hide\n ylims!(-3, 3) # hide\n else # hide\n scatter(dataset[1, :], dataset[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n legend=false, # hide\n ) # hide\n noisy_data = forward(scheduler, dataset, noise, [t]) # hide\n plot = scatter!(noisy_data[1, :], noisy_data[2, :], # hide\n alpha=0.5, # hide\n aspectratio=:equal, # hide\n ) # hide\n title!(string(beta_schedule)) # hide\n xlims!(-3, 3) # hide\n ylims!(-3, 3) # hide\n end # hide\n push!(plots, plot) # hide\n end # hide\n plot(plots...; size=(1200, 800)) # hide\nend # hide\n\ngif(anim, anim.dir * \".gif\", fps=20) # hide","category":"page"},{"location":"generated/beta_schedulers_comparison/#Double-Square","page":"Beta Schedules Comparison","title":"Double Square","text":"","category":"section"},{"location":"generated/beta_schedulers_comparison/","pa
|