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

Commit b005eed

Browse files
committed
Set fixed Seed on realtime start
1 parent 3ed36b1 commit b005eed

File tree

6 files changed

+181
-71
lines changed

6 files changed

+181
-71
lines changed

OnnxStack.UI/UserControls/SchedulerControl.xaml

Lines changed: 114 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,117 @@
2626
</StackPanel>
2727
</TabItem.Header>
2828
<StackPanel Margin="2">
29-
<StackPanel>
30-
<Label>Scheduler</Label>
31-
<ComboBox ItemsSource="{Binding SchedulerTypes}" SelectedItem="{Binding SchedulerOptions.SchedulerType}"/>
32-
</StackPanel>
33-
<UniformGrid Columns="4" Margin="0,2,0,0">
34-
<StackPanel>
35-
<Label>Seed</Label>
36-
<TextBox Text="{Binding SchedulerOptions.Seed}"/>
37-
</StackPanel>
38-
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Left">
39-
<Button Command="{Binding RandomSeedCommand}" Height="22" Width="22" BorderThickness="0,1,1,1">
40-
<userControls:FontAwesome Icon="&#xf074;" IconStyle="Light"/>
41-
</Button>
42-
</StackPanel>
43-
<StackPanel Margin="1,0,1,0">
44-
<Label>Width</Label>
45-
<ComboBox ItemsSource="{Binding ValidSizes}" SelectedItem="{Binding SchedulerOptions.Width}" />
29+
<UniformGrid Columns="2">
30+
<StackPanel Margin="0,0,5,0">
31+
<Label>Scheduler</Label>
32+
<ComboBox ItemsSource="{Binding SchedulerTypes}" SelectedItem="{Binding SchedulerOptions.SchedulerType}"/>
4633
</StackPanel>
47-
<StackPanel>
48-
<Label>Height</Label>
49-
<ComboBox ItemsSource="{Binding ValidSizes}" SelectedItem="{Binding SchedulerOptions.Height}" />
34+
35+
<StackPanel Orientation="Horizontal" Margin="0,9,0,0">
36+
<StackPanel Orientation="Horizontal" Margin="5,8,0,0">
37+
<Ellipse Fill="Red" Width="15" Height="15" >
38+
<Ellipse.Triggers>
39+
<EventTrigger RoutedEvent="Ellipse.Loaded">
40+
<EventTrigger.Actions>
41+
<BeginStoryboard>
42+
<Storyboard>
43+
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(Ellipse.Opacity)"
44+
Duration="0:0:6"
45+
FillBehavior="Stop"
46+
RepeatBehavior="Forever"
47+
AutoReverse="False">
48+
<DoubleAnimationUsingKeyFrames.KeyFrames>
49+
<EasingDoubleKeyFrame KeyTime="0:0:0" Value=".5"/>
50+
<EasingDoubleKeyFrame KeyTime="0:0:3" Value=".8"/>
51+
<EasingDoubleKeyFrame KeyTime="0:0:6" Value=".5"/>
52+
</DoubleAnimationUsingKeyFrames.KeyFrames>
53+
</DoubleAnimationUsingKeyFrames>
54+
</Storyboard>
55+
</BeginStoryboard>
56+
</EventTrigger.Actions>
57+
</EventTrigger>
58+
</Ellipse.Triggers>
59+
</Ellipse>
60+
<StackPanel.Style>
61+
<Style TargetType="{x:Type StackPanel}">
62+
<Setter Property="Visibility" Value="Collapsed" />
63+
<Style.Triggers>
64+
<MultiDataTrigger>
65+
<MultiDataTrigger.Conditions>
66+
<Condition Binding="{Binding BatchOptions.IsRealtimeEnabled}" Value="True" />
67+
</MultiDataTrigger.Conditions>
68+
<MultiDataTrigger.Setters>
69+
<Setter Property="Visibility" Value="Visible" />
70+
</MultiDataTrigger.Setters>
71+
</MultiDataTrigger>
72+
</Style.Triggers>
73+
</Style>
74+
</StackPanel.Style>
75+
76+
</StackPanel>
77+
78+
<StackPanel Orientation="Horizontal" Margin="5,8,0,0">
79+
<Ellipse Fill="{StaticResource ControlDisabledBorderBrush}" Width="15" Height="15" />
80+
81+
<StackPanel.Style>
82+
<Style TargetType="{x:Type StackPanel}">
83+
<Setter Property="Visibility" Value="Visible" />
84+
<Style.Triggers>
85+
<MultiDataTrigger>
86+
<MultiDataTrigger.Conditions>
87+
<Condition Binding="{Binding BatchOptions.IsRealtimeEnabled}" Value="True" />
88+
</MultiDataTrigger.Conditions>
89+
<MultiDataTrigger.Setters>
90+
<Setter Property="Visibility" Value="Collapsed" />
91+
</MultiDataTrigger.Setters>
92+
</MultiDataTrigger>
93+
</Style.Triggers>
94+
</Style>
95+
</StackPanel.Style>
96+
</StackPanel>
97+
98+
99+
100+
101+
<CheckBox IsChecked="{Binding BatchOptions.IsRealtimeEnabled}" IsEnabled="{Binding BatchOptions.IsAutomationEnabled, Converter={StaticResource InverseBoolConverter}}" Content="Enable Live Update" Margin="4,12,0,0" />
50102
</StackPanel>
103+
104+
105+
</UniformGrid>
106+
107+
108+
<UniformGrid Columns="2" >
109+
<DockPanel Margin="0,0,5,0">
110+
<UniformGrid DockPanel.Dock="Right" Columns="2" VerticalAlignment="Bottom" >
111+
<Button Command="{Binding NewSeedCommand}" BorderThickness="0,1,1,1" ToolTip="New Seed" Width="25">
112+
<userControls:FontAwesome Icon="&#xf051;" IconStyle="Light" Size="15"/>
113+
</Button>
114+
<Button Command="{Binding RandomSeedCommand}" BorderThickness="0,1,1,1" ToolTip="Random Seeds">
115+
<userControls:FontAwesome Icon="&#xf074;" IconStyle="Light"/>
116+
</Button>
117+
</UniformGrid>
118+
119+
<StackPanel>
120+
<Label>Seed</Label>
121+
<TextBox Text="{Binding SchedulerOptions.Seed}"/>
122+
</StackPanel>
123+
124+
</DockPanel>
125+
126+
<UniformGrid Columns="2" Margin="5,0,0,0">
127+
<StackPanel Margin="1,0,1,0">
128+
<Label>Width</Label>
129+
<ComboBox ItemsSource="{Binding ValidSizes}" SelectedItem="{Binding SchedulerOptions.Width}" />
130+
</StackPanel>
131+
<StackPanel>
132+
<Label>Height</Label>
133+
<ComboBox ItemsSource="{Binding ValidSizes}" SelectedItem="{Binding SchedulerOptions.Height}" />
134+
</StackPanel>
135+
</UniformGrid>
136+
51137
</UniformGrid>
52138

53-
<UniformGrid Columns="2" Margin="0,10,0,0">
139+
<UniformGrid Columns="2" Margin="0,5,0,0">
54140
<StackPanel Margin="0,0,5,0">
55141
<DockPanel >
56142
<Label>Inference Steps</Label>
@@ -75,7 +161,7 @@
75161
</StackPanel>
76162
</UniformGrid>
77163

78-
<UniformGrid Columns="2" Margin="0,10,0,0">
164+
<UniformGrid Columns="2" Margin="0,5,0,0">
79165

80166

81167
<StackPanel Margin="0,0,5,0">
@@ -165,10 +251,7 @@
165251
</UniformGrid>
166252

167253
<UniformGrid>
168-
<Button Command="{Binding ResetParametersCommand}" Margin="0,5,0,0" HorizontalAlignment="Left">
169-
<userControls:FontAwesome Icon="&#xf2ea;" IconStyle="Light" Size="14" Margin="2"/>
170-
</Button>
171-
<CheckBox IsChecked="{Binding BatchOptions.IsRealtimeEnabled}" IsEnabled="{Binding BatchOptions.IsAutomationEnabled, Converter={StaticResource InverseBoolConverter}}" Content="Enable Live Update" HorizontalAlignment="Right" VerticalAlignment="Bottom" />
254+
172255
</UniformGrid>
173256
</StackPanel>
174257
</TabItem>
@@ -184,8 +267,8 @@
184267
<StackPanel Margin="2">
185268

186269
<UniformGrid Columns="2" Margin="0,10, 0, 0">
187-
188-
270+
271+
189272
</UniformGrid>
190273

191274
<UniformGrid Columns="3">
@@ -219,7 +302,7 @@
219302
</UniformGrid>
220303

221304
<UniformGrid Columns="3">
222-
305+
223306
<StackPanel>
224307
<Label>BetaStart</Label>
225308
<TextBox Text="{Binding SchedulerOptions.BetaStart}"/>
@@ -235,7 +318,7 @@
235318
</UniformGrid>
236319

237320
<UniformGrid Columns="3">
238-
321+
239322
<StackPanel Margin="1,0,1,0">
240323
<Label>ClipSampleRange</Label>
241324
<TextBox Text="{Binding SchedulerOptions.ClipSampleRange}"/>
@@ -417,7 +500,7 @@
417500
</StackPanel.Style>
418501
</StackPanel>
419502

420-
503+
421504
</StackPanel>
422505
</StackPanel>
423506
</StackPanel>

OnnxStack.UI/UserControls/SchedulerControl.xaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ public partial class SchedulerControl : UserControl, INotifyPropertyChanged
2828
public SchedulerControl()
2929
{
3030
ValidSizes = new ObservableCollection<int>(Constants.ValidSizes);
31+
NewSeedCommand = new RelayCommand(NewSeed);
3132
RandomSeedCommand = new RelayCommand(RandomSeed);
3233
ResetParametersCommand = new RelayCommand(ResetParameters);
3334
InitializeComponent();
3435
}
3536

3637
public ICommand ResetParametersCommand { get; }
38+
public ICommand NewSeedCommand { get; }
3739
public ICommand RandomSeedCommand { get; }
3840
public ObservableCollection<int> ValidSizes { get; }
3941

@@ -164,11 +166,16 @@ private void ResetParameters()
164166
};
165167
}
166168

167-
private void RandomSeed()
169+
private void NewSeed()
168170
{
169171
SchedulerOptions.Seed = Random.Shared.Next();
170172
}
171173

174+
private void RandomSeed()
175+
{
176+
SchedulerOptions.Seed = 0;
177+
}
178+
172179
#region INotifyPropertyChanged
173180
public event PropertyChangedEventHandler PropertyChanged;
174181
public void NotifyPropertyChanged([CallerMemberName] string property = "")

OnnxStack.UI/Views/ImageInpaintView.xaml.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,27 +337,33 @@ private async IAsyncEnumerable<ImageResult> ExecuteStableDiffusion(IModelOptions
337337
yield break;
338338

339339
_cancelationTokenSource = new CancellationTokenSource();
340-
if (!BatchOptions.IsAutomationEnabled)
341-
{
342-
var timestamp = Stopwatch.GetTimestamp();
343-
var result = await _stableDiffusionService.GenerateAsBytesAsync(modelOptions, promptOptions, schedulerOptions, ProgressCallback(), _cancelationTokenSource.Token);
344-
yield return await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
345-
}
346-
else
340+
341+
if (!BatchOptions.IsRealtimeEnabled)
347342
{
348-
if (!BatchOptions.IsRealtimeEnabled)
343+
if (!BatchOptions.IsAutomationEnabled)
349344
{
350345
var timestamp = Stopwatch.GetTimestamp();
351-
await foreach (var batchResult in _stableDiffusionService.GenerateBatchAsync(modelOptions, promptOptions, schedulerOptions, batchOptions, ProgressBatchCallback(), _cancelationTokenSource.Token))
346+
var result = await _stableDiffusionService.GenerateAsBytesAsync(modelOptions, promptOptions, schedulerOptions, ProgressCallback(), _cancelationTokenSource.Token);
347+
yield return await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
348+
}
349+
else
350+
{
351+
if (!BatchOptions.IsRealtimeEnabled)
352352
{
353-
yield return await GenerateResultAsync(batchResult.ImageResult.ToImageBytes(), promptOptions, batchResult.SchedulerOptions, timestamp);
354-
timestamp = Stopwatch.GetTimestamp();
353+
var timestamp = Stopwatch.GetTimestamp();
354+
await foreach (var batchResult in _stableDiffusionService.GenerateBatchAsync(modelOptions, promptOptions, schedulerOptions, batchOptions, ProgressBatchCallback(), _cancelationTokenSource.Token))
355+
{
356+
yield return await GenerateResultAsync(batchResult.ImageResult.ToImageBytes(), promptOptions, batchResult.SchedulerOptions, timestamp);
357+
timestamp = Stopwatch.GetTimestamp();
358+
}
355359
}
356-
yield break;
357360
}
358-
361+
}
362+
else
363+
{
359364
// Realtime Diffusion
360365
IsControlsEnabled = true;
366+
SchedulerOptions.Seed = SchedulerOptions.Seed == 0 ? Random.Shared.Next() : SchedulerOptions.Seed;
361367
while (!_cancelationTokenSource.IsCancellationRequested)
362368
{
363369
var refreshTimestamp = Stopwatch.GetTimestamp();

OnnxStack.UI/Views/ImageToImageView.xaml.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,27 +319,34 @@ private async IAsyncEnumerable<ImageResult> ExecuteStableDiffusion(IModelOptions
319319
yield break;
320320

321321
_cancelationTokenSource = new CancellationTokenSource();
322-
if (!BatchOptions.IsAutomationEnabled)
323-
{
324-
var timestamp = Stopwatch.GetTimestamp();
325-
var result = await _stableDiffusionService.GenerateAsBytesAsync(modelOptions, promptOptions, schedulerOptions, ProgressCallback(), _cancelationTokenSource.Token);
326-
yield return await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
327-
}
328-
else
322+
323+
if (!BatchOptions.IsRealtimeEnabled)
329324
{
330-
if (!BatchOptions.IsRealtimeEnabled)
325+
if (!BatchOptions.IsAutomationEnabled)
331326
{
332327
var timestamp = Stopwatch.GetTimestamp();
333-
await foreach (var batchResult in _stableDiffusionService.GenerateBatchAsync(modelOptions, promptOptions, schedulerOptions, batchOptions, ProgressBatchCallback(), _cancelationTokenSource.Token))
328+
var result = await _stableDiffusionService.GenerateAsBytesAsync(modelOptions, promptOptions, schedulerOptions, ProgressCallback(), _cancelationTokenSource.Token);
329+
yield return await GenerateResultAsync(result, promptOptions, schedulerOptions, timestamp);
330+
}
331+
else
332+
{
333+
if (!BatchOptions.IsRealtimeEnabled)
334334
{
335-
yield return await GenerateResultAsync(batchResult.ImageResult.ToImageBytes(), promptOptions, batchResult.SchedulerOptions, timestamp);
336-
timestamp = Stopwatch.GetTimestamp();
335+
var timestamp = Stopwatch.GetTimestamp();
336+
await foreach (var batchResult in _stableDiffusionService.GenerateBatchAsync(modelOptions, promptOptions, schedulerOptions, batchOptions, ProgressBatchCallback(), _cancelationTokenSource.Token))
337+
{
338+
yield return await GenerateResultAsync(batchResult.ImageResult.ToImageBytes(), promptOptions, batchResult.SchedulerOptions, timestamp);
339+
timestamp = Stopwatch.GetTimestamp();
340+
}
341+
337342
}
338-
yield break;
339343
}
340-
344+
}
345+
else
346+
{
341347
// Realtime Diffusion
342348
IsControlsEnabled = true;
349+
SchedulerOptions.Seed = SchedulerOptions.Seed == 0 ? Random.Shared.Next() : SchedulerOptions.Seed;
343350
while (!_cancelationTokenSource.IsCancellationRequested)
344351
{
345352
var refreshTimestamp = Stopwatch.GetTimestamp();

OnnxStack.UI/Views/PaintToImageView.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ private async IAsyncEnumerable<ImageResult> ExecuteStableDiffusion(IModelOptions
356356
{
357357
// Realtime Diffusion
358358
IsControlsEnabled = true;
359+
SchedulerOptions.Seed = SchedulerOptions.Seed == 0 ? Random.Shared.Next() : SchedulerOptions.Seed;
359360
while (!_cancelationTokenSource.IsCancellationRequested)
360361
{
361362
var refreshTimestamp = Stopwatch.GetTimestamp();

0 commit comments

Comments
 (0)