Skip to content
This repository was archived by the owner on Nov 27, 2024. It is now read-only.

Commit cd637a3

Browse files
committed
ControlNet VideoToVideo Support
1 parent 1e5aede commit cd637a3

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

OnnxStack.StableDiffusion/Diffusers/DiffuserBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public virtual async Task<DenseTensor<float>> DiffuseAsync(ModelOptions modelOpt
124124
foreach (var videoFrame in videoFrames)
125125
{
126126
frameIndex++;
127-
promptOptions.InputImage = new InputImage(videoFrame);
127+
promptOptions.InputImage = promptOptions.DiffuserType == DiffuserType.ControlNet ? default : new InputImage(videoFrame);
128+
promptOptions.InputContolImage = promptOptions.DiffuserType == DiffuserType.ImageToImage ? default : new InputImage(videoFrame);
128129
var frameResultTensor = await SchedulerStepAsync(modelOptions, promptOptions, schedulerOptions, promptEmbeddings, performGuidance, schedulerFrameCallback, cancellationToken);
129130

130131
// Frame Progress

OnnxStack.UI/Views/VideoToVideoView.xaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@
2020
<Button Content="Generate" Command="{Binding GenerateCommand}" IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}" IsDefault="True" Margin="1,0,0,0"/>
2121
</UniformGrid>
2222
<DockPanel>
23-
<userControls:ModelPickerControl DockPanel.Dock="Top"
24-
UISettings="{Binding UISettings}"
25-
SupportedDiffusers="{Binding SupportedDiffusers}"
26-
IsEnabled="{Binding IsGenerating, Converter={StaticResource InverseBoolConverter}}"
27-
SelectedModel="{Binding SelectedModel, Mode=TwoWay}"/>
23+
<StackPanel DockPanel.Dock="Top">
24+
<userControls:ModelPickerControl
25+
UISettings="{Binding UISettings}"
26+
SupportedDiffusers="{Binding SupportedDiffusers}"
27+
IsEnabled="{Binding IsGenerating, Converter={StaticResource InverseBoolConverter}}"
28+
SelectedModel="{Binding SelectedModel, Mode=TwoWay}"/>
29+
<userControls:ControlNetPickerControl
30+
UISettings="{Binding UISettings}"
31+
IsEnabled="{Binding IsGenerating, Converter={StaticResource InverseBoolConverter}}"
32+
SelectedModel="{Binding SelectedControlNetModel, Mode=TwoWay}"
33+
Visibility="{Binding SelectedModel.IsControlNet, Converter={StaticResource BooleanToVisibilityConverter}, FallbackValue=Collapsed}"/>
34+
</StackPanel>
2835
<DockPanel IsEnabled="{Binding SelectedModel.IsLoaded, FallbackValue=False, TargetNullValue=False}">
2936
<userControls:SchedulerControl DockPanel.Dock="Bottom" Margin="0, 10, 0 ,0"
3037
SelectedModel="{Binding SelectedModel}"

OnnxStack.UI/Views/VideoToVideoView.xaml.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public partial class VideoToVideoView : UserControl, INavigatable, INotifyProper
4444
private VideoInputModel _inputVideo;
4545
private VideoInputModel _resultVideo;
4646
private StableDiffusionModelSetViewModel _selectedModel;
47+
private ControlNetModelSetViewModel _selectedControlNetModel;
4748
private PromptOptionsModel _promptOptionsModel;
4849
private SchedulerOptionsModel _schedulerOptions;
4950
private CancellationTokenSource _cancelationTokenSource;
@@ -63,7 +64,7 @@ public VideoToVideoView()
6364
_stableDiffusionService = App.GetService<IStableDiffusionService>();
6465
}
6566

66-
SupportedDiffusers = new() { DiffuserType.ImageToImage };
67+
SupportedDiffusers = new() { DiffuserType.ImageToImage, DiffuserType.ControlNet };
6768
CancelCommand = new AsyncRelayCommand(Cancel, CanExecuteCancel);
6869
GenerateCommand = new AsyncRelayCommand(Generate, CanExecuteGenerate);
6970
ClearHistoryCommand = new AsyncRelayCommand(ClearHistory, CanExecuteClearHistory);
@@ -95,6 +96,12 @@ public StableDiffusionModelSetViewModel SelectedModel
9596
set { _selectedModel = value; NotifyPropertyChanged(); }
9697
}
9798

99+
public ControlNetModelSetViewModel SelectedControlNetModel
100+
{
101+
get { return _selectedControlNetModel; }
102+
set { _selectedControlNetModel = value; NotifyPropertyChanged(); }
103+
}
104+
98105
public PromptOptionsModel PromptOptions
99106
{
100107
get { return _promptOptionsModel; }
@@ -215,7 +222,7 @@ private async Task Generate()
215222
var promptOptions = GetPromptOptions(PromptOptions, _videoFrames);
216223

217224
var timestamp = Stopwatch.GetTimestamp();
218-
var result = await _stableDiffusionService.GenerateAsBytesAsync(new ModelOptions(_selectedModel.ModelSet), promptOptions, schedulerOptions, ProgressCallback(), _cancelationTokenSource.Token);
225+
var result = await _stableDiffusionService.GenerateAsBytesAsync(new ModelOptions(_selectedModel.ModelSet, _selectedControlNetModel?.ModelSet), promptOptions, schedulerOptions, ProgressCallback(), _cancelationTokenSource.Token);
219226
var resultVideo = await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
220227
if (resultVideo != null)
221228
{
@@ -247,7 +254,9 @@ private async Task Generate()
247254
/// </returns>
248255
private bool CanExecuteGenerate()
249256
{
250-
return !IsGenerating && HasInputResult;
257+
return !IsGenerating
258+
&& HasInputResult
259+
&& (!SelectedModel.IsControlNet || (SelectedModel.IsControlNet && SelectedControlNetModel?.IsLoaded == true));
251260
}
252261

253262

@@ -314,11 +323,19 @@ private void Reset()
314323

315324
private PromptOptions GetPromptOptions(PromptOptionsModel promptOptionsModel, VideoFrames videoFrames)
316325
{
326+
var diffuserType = DiffuserType.ImageToImage;
327+
if (_selectedModel.IsControlNet)
328+
{
329+
diffuserType = _schedulerOptions.Strength >= 1
330+
? DiffuserType.ControlNet
331+
: DiffuserType.ControlNetImage;
332+
}
333+
317334
return new PromptOptions
318335
{
319336
Prompt = promptOptionsModel.Prompt,
320337
NegativePrompt = promptOptionsModel.NegativePrompt,
321-
DiffuserType = DiffuserType.ImageToImage,
338+
DiffuserType = diffuserType,
322339
InputVideo = new VideoInput(videoFrames),
323340
VideoInputFPS = promptOptionsModel.VideoInputFPS,
324341
VideoOutputFPS = promptOptionsModel.VideoOutputFPS,

0 commit comments

Comments
 (0)