1
1
package main
2
2
3
3
import (
4
- "io"
5
4
"os"
6
5
7
6
"github.com/ring-c/go-web-diff/pkg/opts"
8
7
"github.com/ring-c/go-web-diff/pkg/sd"
9
8
)
10
9
11
10
func main () {
12
-
13
11
options := sd .DefaultOptions
14
12
options .GpuEnable = true
15
13
options .Wtype = opts .F16
16
14
options .Schedule = opts .KARRAS
15
+ options .Debug = true
17
16
18
17
model , err := sd .NewModel (options )
19
18
if err != nil {
@@ -30,56 +29,74 @@ func main() {
30
29
return
31
30
}
32
31
33
- filenames := []string {
34
- "./output/0.png" ,
32
+ // println(model.GetSystemInfo())
33
+
34
+ err = generate (model )
35
+ if err != nil {
36
+ println (err .Error ())
37
+ return
35
38
}
36
39
37
- var writers []io. Writer
38
- for _ , filename := range filenames {
39
- var file * os. File
40
- file , err = os . Create ( filename )
41
- if err != nil {
42
- println ( err . Error ())
43
- return
44
- }
45
-
46
- writers = append ( writers , file )
47
- defer func () {
48
- _ = file . Close ( )
49
- }()
40
+ // err = upscale(model)
41
+ // if err != nil {
42
+ // println(err.Error())
43
+ // return
44
+ // }
45
+ }
46
+
47
+ func generate ( model * sd. Model ) ( err error ) {
48
+ var file * os. File
49
+ file , err = os . Create ( "./output/0.png" )
50
+ if err != nil {
51
+ println ( err . Error () )
52
+ return
50
53
}
51
54
55
+ defer func () {
56
+ _ = file .Close ()
57
+ }()
58
+
52
59
var params = sd .DefaultFullParams
53
60
params .Width = 1024
54
61
params .Height = 1024
55
62
params .CfgScale = 2
56
- params .SampleSteps = 32
63
+ params .SampleSteps = 4
57
64
params .SampleMethod = opts .EULER_A
58
- params .BatchCount = len ( writers )
65
+ params .Seed = 4242
59
66
60
- err = model .Predict ("1wolf, forest, full body" , params , writers )
67
+ err = model .Predict ("1girl, indoors, full body" , params , file )
68
+ if err != nil {
69
+ return
70
+ }
71
+
72
+ return
73
+ }
74
+
75
+ /*
76
+ func upscale(model *sd.Model) (err error) {
77
+ fileRead, err := os.Open("./output/0.png")
78
+ if err != nil {
79
+ return
80
+ }
81
+
82
+ defer func() {
83
+ _ = fileRead.Close()
84
+ }()
85
+
86
+ fileWrite, err := os.Create("./output/1.png")
87
+ if err != nil {
88
+ return
89
+ }
90
+
91
+ defer func() {
92
+ _ = fileWrite.Close()
93
+ }()
94
+
95
+ err = model.UpscaleImage(fileRead, "/media/ed/files/sd/models/ESRGAN/RealESRGAN_x4plus_anime_6B.pth", 2, fileWrite)
61
96
if err != nil {
62
- println (err .Error ())
63
97
return
64
98
}
65
99
66
- /*
67
- fileRead, err := os.Open("./output/1.png")
68
- if err != nil {
69
- println(err.Error())
70
- return
71
- }
72
-
73
- fileWrite, err := os.Create("./output/2.png")
74
- if err != nil {
75
- println(err.Error())
76
- return
77
- }
78
-
79
- err = model.UpscaleImage(fileRead, "/media/ed/files/sd/models/ESRGAN/RealESRGAN_x4plus_anime_6B.pth", 2, fileWrite)
80
- if err != nil {
81
- println(err.Error())
82
- return
83
- }
84
- */
100
+ return
85
101
}
102
+ */
0 commit comments