-
Notifications
You must be signed in to change notification settings - Fork 6
/
sd_test.go
148 lines (141 loc) · 2.93 KB
/
sd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package sd_test
import (
sd "github.com/seasonjs/stable-diffusion"
"io"
"os"
"testing"
)
func TestNewStableDiffusionAutoModelPredict(t *testing.T) {
options := sd.DefaultOptions
t.Log(options)
model, err := sd.NewAutoModel(options)
if err != nil {
t.Error(err)
return
}
defer model.Close()
model.SetLogCallback(func(level sd.LogLevel, msg string) {
t.Log(msg)
})
err = model.LoadFromFile("./models/miniSD.ckpt")
if err != nil {
t.Error(err)
return
}
var writers []io.Writer
filenames := []string{
"./assets/love_cat2.png",
}
for _, filename := range filenames {
file, err := os.Create(filename)
if err != nil {
t.Error(err)
return
}
defer file.Close()
writers = append(writers, file)
}
params := sd.DefaultFullParams
params.BatchCount = 1
params.Width = 256
params.Height = 256
params.NegativePrompt = ""
err = model.Predict("british short hair cat, high quality", params, writers)
if err != nil {
t.Error(err)
return
}
}
func TestModel_ROCm(t *testing.T) {
options := sd.DefaultOptions
options.GpuEnable = true
t.Log(options)
model, err := sd.NewAutoModel(options)
if err != nil {
t.Error(err)
return
}
defer model.Close()
model.SetLogCallback(func(level sd.LogLevel, msg string) {
t.Log(msg)
})
err = model.LoadFromFile("./models/miniSD.ckpt")
if err != nil {
t.Error(err)
return
}
var writers []io.Writer
filenames := []string{
"./assets/love_cat2.png",
}
for _, filename := range filenames {
file, err := os.Create(filename)
if err != nil {
t.Error(err)
return
}
defer file.Close()
writers = append(writers, file)
}
params := sd.DefaultFullParams
params.BatchCount = 1
params.Width = 256
params.Height = 256
params.NegativePrompt = ""
err = model.Predict("british short hair cat, high quality", params, writers)
if err != nil {
t.Error(err)
return
}
}
func TestNewStableDiffusionAutoModelImagePredict(t *testing.T) {
options := sd.DefaultOptions
options.VaeDecodeOnly = false
t.Log(options)
model, err := sd.NewAutoModel(options)
if err != nil {
t.Error(err)
return
}
defer model.Close()
model.SetLogCallback(func(level sd.LogLevel, msg string) {
t.Log(msg)
})
err = model.LoadFromFile("./models/mysd.safetensors")
if err != nil {
t.Error(err)
return
}
inFile, err := os.Open("./assets/love_cat0.png")
if err != nil {
t.Error(err)
return
}
defer inFile.Close()
var writers []io.Writer
filenames := []string{
"./assets/love_cat0_m.png",
//"./assets/love_cat1_m.png",
//"./assets/love_cat5.png",
//"./assets/love_cat6.png"
}
for _, filename := range filenames {
file, err := os.Create(filename)
if err != nil {
t.Error(err)
return
}
defer file.Close()
writers = append(writers, file)
}
params := sd.DefaultFullParams
params.BatchCount = 1
params.Width = 256
params.Height = 256
params.NegativePrompt = ""
err = model.ImagePredict(inFile, "dogs", params, writers)
if err != nil {
t.Error(err)
return
}
}