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

Commit b6f8b54

Browse files
authored
Merge pull request #93 from jeffward01/master
Example project fixes and readme additions
2 parents 29826f9 + 860f0db commit b6f8b54

File tree

5 files changed

+118
-1
lines changed

5 files changed

+118
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# User-specific files (MonoDevelop/Xamarin Studio)
1313
*.userprefs
1414

15+
# Downloaded .onnx files
16+
onnx-models/
17+
1518
# Build results
1619
[Dd]ebug/
1720
[Dd]ebugPublic/

OnnxStack.Console/Examples/StableDiffusionBatch.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
namespace OnnxStack.Console.Runner
1010
{
11+
using StableDiffusion;
12+
1113
public sealed class StableDiffusionBatch : IExampleRunner
1214
{
1315
private readonly string _outputDirectory;
@@ -56,6 +58,8 @@ public async Task RunAsync()
5658

5759
foreach (var model in _configuration.ModelSets)
5860
{
61+
_setSchedulerTypeForPipeline();
62+
5963
OutputHelpers.WriteConsole($"Loading Model `{model.Name}`...", ConsoleColor.Green);
6064
await _stableDiffusionService.LoadModelAsync(model);
6165

@@ -76,6 +80,13 @@ public async Task RunAsync()
7680

7781
OutputHelpers.WriteConsole($"Unloading Model `{model.Name}`...", ConsoleColor.Green);
7882
await _stableDiffusionService.UnloadModelAsync(model);
83+
continue;
84+
85+
void _setSchedulerTypeForPipeline()
86+
{
87+
SchedulerType[] scheduleTypes = model.PipelineType.GetSchedulerTypes();
88+
schedulerOptions.SchedulerType = scheduleTypes.Length == 1 ? scheduleTypes[0] : scheduleTypes[Random.Shared.Next(scheduleTypes.Length)];
89+
}
7990
}
8091
}
8192
}

OnnxStack.Console/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Example - Console App
2+
3+
## Getting Started
4+
5+
### 1.) Download the required `.onnx` models:
6+
7+
**Method 1**
8+
9+
Download the required models from the following repositories:
10+
11+
* https://huggingface.co/rocca/swin-ir-onnx
12+
* This is the upscaler model.
13+
* https://huggingface.co/runwayml/stable-diffusion-v1-5
14+
* https://huggingface.co/softwareweaver/InstaFlow-0.9B-Olive-Onnx
15+
* https://huggingface.co/SimianLuo/LCM_Dreamshaper_v7
16+
* https://huggingface.co/softwareweaver/stable-diffusion-xl-base-1.0-Olive-Onnx
17+
18+
19+
Note: Ensure you run ```git lfs install``` before cloning the repository to ensure the models are downloaded correctly.
20+
21+
22+
23+
24+
25+
26+
27+
**Method 2**
28+
29+
Download Files
30+
31+
**Experimental script**
32+
33+
_Note: The `download-models.bat` file is not smart enough to know if you have already downloaded the models. If you need to re-download the models, please run the commands manually within `git` to pull the latest changes from the target repository._
34+
35+
> If your on mac or linux, you can open the `download-models.bat` file and run each command manually if you are unable to run the `.bat` file.
36+
37+
Use the included `download-models.bat` file to download the required models.
38+
39+
* The `download-models.bat` will create a `onnx-models/` folder in current directory. Then it will download the required models into the `onnx-models/` folder.
40+
* If you are unable to run the `.bat` file or have issues, you can open the `download-models.bat` file and run each command manually.
41+
* The `.bat` file will not attempt to 're-download' or continue if the file already exists. If you need to re-download the models, delete the `onnx-models/` folder and run the `.bat` file again.
42+
43+
44+
### 2.) If necessary, switch to the correct Stable Diffusion 1.5 branch
45+
46+
**Stable Diffusion 1.5 - Get the .onnx files after download.**
47+
48+
* After you download the `Stable Diffusion 1.5` model at: https://huggingface.co/runwayml/stable-diffusion-v1-5, check to see if any of the folders contain `.onnx` files.
49+
* If none contain `.onnx` files, you will need to switch to the `.onnx` branch.
50+
* If you have already checked out the `onnx` branch and have the `.onnx` files from the `Stable Diffusion 1.5` repository, you can skip this step.
51+
52+
53+
We need to switch to the `onnx` branch to get the `.onnx` files.
54+
You can do this anyway you would like, or just run the following commands:
55+
* Open a new command prompt in `onnx-models/stable-diffusion-v1-5/`
56+
```bash
57+
git fetch origin
58+
git checkout origin/onnx
59+
```
60+
_It might take some time to switch branches and download all of the `.onnx` files pending your internet speed._
61+
62+
63+
64+
### 3.) Update the paths in the `appsettings.json` within the `/OnnxStack.Console/` project:
65+
66+
67+
* Update the paths in `appsettings.json` to point to the downloaded models. Update all the paths to point to the correct location of the downloaded models.
68+
* If the downloaded model repository does not contain a `Tokenizer` or `Tokenizer2` `.onnx` file, leave the path empty.
69+
* Note: When the path is empty, OnnxStack will use it's own 'built-in' _default_ tokenizer called `cliptokenizer.onnx`
70+
* Example with empty path:
71+
```json
72+
{
73+
"Type": "Tokenizer",
74+
"OnnxModelPath": ""
75+
},
76+
{
77+
"Type": "Tokenizer2",
78+
"OnnxModelPath": ""
79+
}
80+
```
81+
82+
83+
### FAQ
84+
85+
* **Q:** My `.GIF` is flashing, is it supposed to do this?
86+
* **A:** The `.GIF` area has been deprecated in favor of the 'video' features that are being added. Please ignore this example for now.
87+
88+
* **Q:** I am getting an error: `138 are out of bounds or can not be read in full`
89+
* **A:** usually means the model is corrupt or has not been fully downloaded, make sure if you clone the repo you have git LFS installed, or you will just get small pointer files not the large GB files
90+
91+
92+
93+
94+

OnnxStack.Console/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
"ExecutionProvider": "DirectML",
206206
"ModelConfigurations": [
207207
{
208-
"Type": "Unet",
208+
"Type": "Upscaler",
209209
"OnnxModelPath": "D:\\Repositories\\upscaler\\SwinIR\\003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.onnx"
210210
}
211211
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mkdir onnx-models
2+
cd onnx-models
3+
git lfs install
4+
git clone https://huggingface.co/rocca/swin-ir-onnx
5+
git clone https://huggingface.co/runwayml/stable-diffusion-v1-5
6+
git clone https://huggingface.co/softwareweaver/InstaFlow-0.9B-Olive-Onnx
7+
git clone https://huggingface.co/SimianLuo/LCM_Dreamshaper_v7
8+
git clone https://huggingface.co/softwareweaver/stable-diffusion-xl-base-1.0-Olive-Onnx
9+

0 commit comments

Comments
 (0)