Browse Source

Fix ReferenceOnly ControlNet batch image outputting original as well

pull/629/head
Ionite 8 months ago
parent
commit
f781fbb229
No known key found for this signature in database
  1. 7
      StabilityMatrix.Avalonia/ViewModels/Inference/Modules/ControlNetModule.cs
  2. 35
      StabilityMatrix.Avalonia/ViewModels/Inference/SamplerCardViewModel.cs
  3. 10
      StabilityMatrix.Core/Models/Inference/ModuleApplyStepTemporaryArgs.cs

7
StabilityMatrix.Avalonia/ViewModels/Inference/Modules/ControlNetModule.cs

@ -114,6 +114,13 @@ public class ControlNetModule : ModuleBase
}
e.Temp.Primary = controlNetReferenceOnly.Output2;
// Indicate that the Primary latent has been temp batched
// https://github.com/comfyanonymous/ComfyUI_experiments/issues/11
e.Temp.IsPrimaryTempBatched = true;
// Index 0 is the original image, index 1 is the reference only latent
e.Temp.PrimaryTempBatchPickIndex = 1;
return;
}

35
StabilityMatrix.Avalonia/ViewModels/Inference/SamplerCardViewModel.cs

@ -222,12 +222,9 @@ public partial class SamplerCardViewModel : LoadableViewModelBase, IParametersLo
);
e.Builder.Connections.Primary = sampler.Output1;
return;
}
// Use KSampler if no refiner, otherwise need KSamplerAdvanced
if (e.Builder.Connections.Refiner.Model is null)
else if (e.Builder.Connections.Refiner.Model is null)
{
// No refiner
var sampler = e.Nodes.AddTypedNode(
@ -272,8 +269,30 @@ public partial class SamplerCardViewModel : LoadableViewModelBase, IParametersLo
}
);
e.Builder.Connections.Primary = sampler.Output;
}
// If temp batched, add a LatentFromBatch to pick the temp batch right after first sampler
if (e.Temp.IsPrimaryTempBatched)
{
e.Builder.Connections.Primary = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.LatentFromBatch
{
Name = e.Nodes.GetUniqueName("ControlNet_LatentFromBatch"),
Samples = e.Builder.GetPrimaryAsLatent(),
BatchIndex = e.Temp.PrimaryTempBatchPickIndex,
// Use max length here as recommended
// https://github.com/comfyanonymous/ComfyUI_experiments/issues/11
Length = 64
}
).Output;
}
// Refiner
if (e.Builder.Connections.Refiner.Model is not null)
{
// Add refiner sampler
var refinerSampler = e.Nodes.AddTypedNode(
e.Builder.Connections.Primary = e.Nodes.AddTypedNode(
new ComfyNodeBuilder.KSamplerAdvanced
{
Name = "Sampler_Refiner",
@ -287,14 +306,12 @@ public partial class SamplerCardViewModel : LoadableViewModelBase, IParametersLo
Positive = refinerConditioning!.Positive,
Negative = refinerConditioning.Negative,
// Connect to previous sampler
LatentImage = sampler.Output,
LatentImage = e.Builder.GetPrimaryAsLatent(),
StartAtStep = Steps,
EndAtStep = TotalSteps,
ReturnWithLeftoverNoise = false
}
);
e.Builder.Connections.Primary = refinerSampler.Output;
).Output;
}
}

10
StabilityMatrix.Core/Models/Inference/ModuleApplyStepTemporaryArgs.cs

@ -11,6 +11,16 @@ public class ModuleApplyStepTemporaryArgs
public VAENodeConnection? PrimaryVAE { get; set; }
/// <summary>
/// Used by Reference-Only ControlNet to indicate that <see cref="Primary"/> has been batched.
/// </summary>
public bool IsPrimaryTempBatched { get; set; }
/// <summary>
/// When <see cref="IsPrimaryTempBatched"/> is true, this is the index of the temp batch to pick after sampling.
/// </summary>
public int PrimaryTempBatchPickIndex { get; set; }
public Dictionary<string, ModelConnections> Models { get; set; } =
new() { ["Base"] = new ModelConnections("Base"), ["Refiner"] = new ModelConnections("Refiner") };

Loading…
Cancel
Save