Skip to content

Commit

Permalink
Merge pull request #100 from saddam213/ControlNet
Browse files Browse the repository at this point in the history
ControlNet Improvements
  • Loading branch information
saddam213 authored Jan 18, 2024
2 parents 3c4e470 + 68fa37f commit 90bb9f1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions OnnxStack.StableDiffusion/Config/ControlNetModelSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace OnnxStack.StableDiffusion.Config
public record ControlNetModelSet : IOnnxModelSetConfig
{
public ControlNetType Type { get; set; }
public DiffuserPipelineType PipelineType { get; set; }
public string Name { get; set; }
public bool IsEnabled { get; set; }
public int DeviceId { get; set; }
Expand Down
18 changes: 12 additions & 6 deletions OnnxStack.UI/Dialogs/AddControlNetModelDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
<DockPanel DataContext="{Binding ElementName=UI}" Margin="15, 15, 15, 10">
<StackPanel DockPanel.Dock="Top">

<StackPanel>
<TextBlock Text="Model Type"/>
<ComboBox ItemsSource="{Binding Source={StaticResource ControlNetType}}" SelectedItem="{Binding SelectedControlNetType}" />
</StackPanel>
<UniformGrid Columns="2">
<StackPanel>
<TextBlock Text="Model Type"/>
<ComboBox ItemsSource="{Binding Source={StaticResource ControlNetType}}" SelectedItem="{Binding SelectedControlNetType}" />
</StackPanel>

<StackPanel Margin="5,0,0,0">
<TextBlock Text="Pipeline Type"/>
<ComboBox ItemsSource="{Binding Source={StaticResource DiffuserPipelineType}}" SelectedItem="{Binding SelectedPipelineType}" />
</StackPanel>
</UniformGrid>

<StackPanel Margin="0,10,0,0">
<TextBlock Text="Control Model File"/>
Expand All @@ -40,7 +46,7 @@
</StackPanel>

<StackPanel Margin="5">


<ItemsControl ItemsSource="{Binding ValidationResults}">
<ItemsControl.ItemTemplate>
Expand All @@ -65,7 +71,7 @@
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

</StackPanel>


Expand Down
11 changes: 10 additions & 1 deletion OnnxStack.UI/Dialogs/AddControlNetModelDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public ControlNetType SelectedControlNetType

}

private DiffuserPipelineType _selectedPipelineType;

public DiffuserPipelineType SelectedPipelineType
{
get { return _selectedPipelineType; }
set { _selectedPipelineType = value; NotifyPropertyChanged(); CreateModelSet(); }
}


public ControlNetModelSet ModelSetResult
{
get { return _modelSetResult; }
Expand All @@ -102,7 +111,7 @@ private void CreateModelSet()
if (string.IsNullOrEmpty(_modelFile))
return;

_modelSetResult = _modelFactory.CreateControlNetModelSet(ModelName.Trim(), _selectedControlNetType, _modelFile, _annotationModelFile);
_modelSetResult = _modelFactory.CreateControlNetModelSet(ModelName.Trim(), _selectedControlNetType, _selectedPipelineType, _modelFile, _annotationModelFile);

// Validate
ValidationResults.Add(new ValidationResult("Name", !_invalidOptions.Contains(_modelName, StringComparer.OrdinalIgnoreCase) && _modelName.Length > 2 && _modelName.Length < 50));
Expand Down
11 changes: 11 additions & 0 deletions OnnxStack.UI/Models/UpdateControlNetModelSetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class UpdateControlNetModelSetViewModel : INotifyPropertyChanged
private ExecutionProvider _executionProvider;
private ObservableCollection<ModelFileViewModel> _modelFiles;
private ControlNetType _controlNetType;
private DiffuserPipelineType _pipelineType;


public string Name
{
Expand All @@ -33,6 +35,13 @@ public ControlNetType ControlNetType
get { return _controlNetType; }
set { _controlNetType = value; NotifyPropertyChanged(); }
}

public DiffuserPipelineType PipelineType
{
get { return _pipelineType; }
set { _pipelineType = value; NotifyPropertyChanged(); }
}

public int DeviceId
{
get { return _deviceId; }
Expand Down Expand Up @@ -76,6 +85,7 @@ public static UpdateControlNetModelSetViewModel FromModelSet(ControlNetModelSet
{
Name = modelset.Name,
ControlNetType = modelset.Type,
PipelineType = modelset.PipelineType,
DeviceId = modelset.DeviceId,
ExecutionMode = modelset.ExecutionMode,
ExecutionProvider = modelset.ExecutionProvider,
Expand Down Expand Up @@ -107,6 +117,7 @@ public static ControlNetModelSet ToModelSet(UpdateControlNetModelSetViewModel mo
IsEnabled = true,
Name = modelset.Name,
Type = modelset.ControlNetType,
PipelineType = modelset.PipelineType,
DeviceId = modelset.DeviceId,
ExecutionMode = modelset.ExecutionMode,
ExecutionProvider = modelset.ExecutionProvider,
Expand Down
2 changes: 1 addition & 1 deletion OnnxStack.UI/Services/IModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface IModelFactory

UpscaleModelSet CreateUpscaleModelSet(string name, string filename, UpscaleModelTemplate modelTemplate);
StableDiffusionModelSet CreateStableDiffusionModelSet(string name, string folder, StableDiffusionModelTemplate modelTemplate);
ControlNetModelSet CreateControlNetModelSet(string name, ControlNetType controlNetType, string modelFilename, string annotationFilename);
ControlNetModelSet CreateControlNetModelSet(string name, ControlNetType controlNetType, DiffuserPipelineType pipelineType, string modelFilename, string annotationFilename);
}
}
3 changes: 2 additions & 1 deletion OnnxStack.UI/Services/ModelFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public UpscaleModelSet CreateUpscaleModelSet(string name, string filename, Upsca
}


public ControlNetModelSet CreateControlNetModelSet(string name, ControlNetType controlNetType, string modelFilename, string annotationFilename)
public ControlNetModelSet CreateControlNetModelSet(string name, ControlNetType controlNetType, DiffuserPipelineType pipelineType, string modelFilename, string annotationFilename)
{
var models = new List<OnnxModelConfig> { new OnnxModelConfig { Type = OnnxModelType.ControlNet, OnnxModelPath = modelFilename } };
if (!string.IsNullOrEmpty(annotationFilename))
Expand All @@ -162,6 +162,7 @@ public ControlNetModelSet CreateControlNetModelSet(string name, ControlNetType c
{
Name = name,
Type = controlNetType,
PipelineType = pipelineType,
ModelConfigurations = models,

IsEnabled = true,
Expand Down

0 comments on commit 90bb9f1

Please sign in to comment.