生成多张
This commit is contained in:
@@ -41,6 +41,29 @@ type Image struct {
|
|||||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// 参数校验
|
||||||
|
//func (img *Image) ParameterCheck() (err error) {
|
||||||
|
// if img.NumInferenceSteps <= 0 {
|
||||||
|
// img.NumInferenceSteps = 20
|
||||||
|
// }
|
||||||
|
// if img.NumInferenceSteps > 500 {
|
||||||
|
// img.NumInferenceSteps = 500
|
||||||
|
// }
|
||||||
|
// if img.GuidanceScale <= 0 {
|
||||||
|
// img.GuidanceScale = 1
|
||||||
|
// }
|
||||||
|
// if img.GuidanceScale > 20 {
|
||||||
|
// img.GuidanceScale = 20
|
||||||
|
// }
|
||||||
|
// if img.Scheduler == "" {
|
||||||
|
// img.Scheduler = "DDIM"
|
||||||
|
// }
|
||||||
|
// if img.Seed == "" {
|
||||||
|
// img.Seed = "0"
|
||||||
|
// }
|
||||||
|
// return
|
||||||
|
//}
|
||||||
|
|
||||||
// 将图片输出为指定尺寸的 webp 格式(默认使用 Lanczos 缩放算法)
|
// 将图片输出为指定尺寸的 webp 格式(默认使用 Lanczos 缩放算法)
|
||||||
func (img *Image) ToWebP(width int, height int, fit string) ([]byte, error) {
|
func (img *Image) ToWebP(width int, height int, fit string) ([]byte, error) {
|
||||||
// 從絕對路徑讀原始圖片
|
// 從絕對路徑讀原始圖片
|
||||||
|
@@ -67,8 +67,6 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (model *Model) Inference(image_list []Image, callback func(Image)) {
|
func (model *Model) Inference(image_list []Image, callback func(Image)) {
|
||||||
log.Println(image_list)
|
|
||||||
|
|
||||||
// 模型未部署到推理機
|
// 模型未部署到推理機
|
||||||
if model.ServerID == "" {
|
if model.ServerID == "" {
|
||||||
//log.Println("模型未部署到推理機, 开始部署模型")
|
//log.Println("模型未部署到推理機, 开始部署模型")
|
||||||
@@ -87,6 +85,7 @@ func (model *Model) Inference(image_list []Image, callback func(Image)) {
|
|||||||
|
|
||||||
// 执行生成任务
|
// 执行生成任务
|
||||||
if model.Image == "" {
|
if model.Image == "" {
|
||||||
|
// 发送的参数
|
||||||
var data = struct {
|
var data = struct {
|
||||||
//EnableHr bool `json:"enable_hr"`
|
//EnableHr bool `json:"enable_hr"`
|
||||||
//DenoisingStrength int `json:"denoising_strength"`
|
//DenoisingStrength int `json:"denoising_strength"`
|
||||||
@@ -109,8 +108,8 @@ func (model *Model) Inference(image_list []Image, callback func(Image)) {
|
|||||||
//SeedResizeFromW int `json:"seed_resize_from_w"`
|
//SeedResizeFromW int `json:"seed_resize_from_w"`
|
||||||
//SamplerName string `json:"sampler_name"`
|
//SamplerName string `json:"sampler_name"`
|
||||||
//BatchSize int `json:"batch_size"`
|
//BatchSize int `json:"batch_size"`
|
||||||
//NIter int `json:"n_iter"`
|
NIter int `json:"n_iter"`
|
||||||
//Steps int `json:"steps"`
|
Steps int `json:"steps"`
|
||||||
//CfgScale int `json:"cfg_scale"`
|
//CfgScale int `json:"cfg_scale"`
|
||||||
//Width int `json:"width"`
|
//Width int `json:"width"`
|
||||||
//Height int `json:"height"`
|
//Height int `json:"height"`
|
||||||
@@ -146,7 +145,7 @@ func (model *Model) Inference(image_list []Image, callback func(Image)) {
|
|||||||
//HrSamplerName: "",
|
//HrSamplerName: "",
|
||||||
//HrPrompt: "",
|
//HrPrompt: "",
|
||||||
//HrNegativePrompt: "",
|
//HrNegativePrompt: "",
|
||||||
Prompt: "miao~",
|
Prompt: image_list[0].Prompt,
|
||||||
//Styles: []string{},
|
//Styles: []string{},
|
||||||
//Seed: -1,
|
//Seed: -1,
|
||||||
//Subseed: -1,
|
//Subseed: -1,
|
||||||
@@ -155,8 +154,8 @@ func (model *Model) Inference(image_list []Image, callback func(Image)) {
|
|||||||
//SeedResizeFromW: -1,
|
//SeedResizeFromW: -1,
|
||||||
//SamplerName: "beamsearch",
|
//SamplerName: "beamsearch",
|
||||||
//BatchSize: 1,
|
//BatchSize: 1,
|
||||||
//NIter: 1,
|
NIter: len(image_list),
|
||||||
//Steps: 50,
|
Steps: 50,
|
||||||
//CfgScale: 7,
|
//CfgScale: 7,
|
||||||
//Width: 512,
|
//Width: 512,
|
||||||
//Height: 512,
|
//Height: 512,
|
||||||
|
@@ -103,15 +103,15 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
// 通过模型推理生成图像, 为图像标记任务批次
|
// 通过模型推理生成图像, 为图像标记任务批次
|
||||||
if match, _ := regexp.MatchString("application/json", r.Header.Get("Content-Type")); match {
|
if match, _ := regexp.MatchString("application/json", r.Header.Get("Content-Type")); match {
|
||||||
template := &struct {
|
template := &struct {
|
||||||
FromImage int `json:"from_image"` // 来源图片(图生图时使用)
|
FromImage int `json:"from_image"` // 来源图片(图生图时使用)
|
||||||
Prompt string `json:"prompt"` // 提示词
|
Prompt string `json:"prompt"` // 提示词
|
||||||
NegativePrompt string `json:"negative_prompt"` // 负面提示词
|
NegativePrompt string `json:"negative_prompt"` // 负面提示词
|
||||||
NumInferenceSteps int `json:"num_inference_steps"` // 推理步数
|
Steps int `json:"steps"` // 推理步数
|
||||||
GuidanceScale float32 `json:"guidance_scale"` // 引导比例
|
GuidanceScale float32 `json:"guidance_scale"` // 引导比例
|
||||||
Scheduler string `json:"scheduler"` // 调度器
|
Scheduler string `json:"scheduler"` // 调度器
|
||||||
Seed string `json:"seed"` // 随机种子(单张图生成时使用)
|
Seed string `json:"seed"` // 随机种子(单张图生成时使用)
|
||||||
Number int `json:"number"` // 生成数量
|
NIter int `json:"n_iter"` // 生成数量
|
||||||
ModelID int `json:"model_id"` // 模型ID
|
ModelID int `json:"model_id"` // 模型ID
|
||||||
}{}
|
}{}
|
||||||
body, err := ioutil.ReadAll(r.Body)
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -125,11 +125,11 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 输入检查
|
// 输入检查
|
||||||
if template.Number <= 0 {
|
if template.NIter <= 0 {
|
||||||
template.Number = 1
|
template.NIter = 1
|
||||||
}
|
}
|
||||||
if template.NumInferenceSteps <= 0 {
|
if template.Steps <= 0 {
|
||||||
template.NumInferenceSteps = 20
|
template.Steps = 50
|
||||||
}
|
}
|
||||||
if template.GuidanceScale <= 0 {
|
if template.GuidanceScale <= 0 {
|
||||||
template.GuidanceScale = 1
|
template.GuidanceScale = 1
|
||||||
@@ -157,7 +157,7 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
// 直接创建一组图片
|
// 直接创建一组图片
|
||||||
var image_list []models.Image
|
var image_list []models.Image
|
||||||
var task string = uuid.New().String()
|
var task string = uuid.New().String()
|
||||||
for i := 0; i < template.Number; i++ {
|
for i := 0; i < template.NIter; i++ {
|
||||||
var image models.Image
|
var image models.Image
|
||||||
image.UserID = account.ID
|
image.UserID = account.ID
|
||||||
image.Task = task
|
image.Task = task
|
||||||
@@ -165,7 +165,7 @@ func ImagesPost(w http.ResponseWriter, r *http.Request) {
|
|||||||
image.FromImage = template.FromImage
|
image.FromImage = template.FromImage
|
||||||
image.Prompt = template.Prompt
|
image.Prompt = template.Prompt
|
||||||
image.NegativePrompt = template.NegativePrompt
|
image.NegativePrompt = template.NegativePrompt
|
||||||
image.NumInferenceSteps = template.NumInferenceSteps
|
image.NumInferenceSteps = template.Steps
|
||||||
image.GuidanceScale = template.GuidanceScale
|
image.GuidanceScale = template.GuidanceScale
|
||||||
image.Scheduler = template.Scheduler
|
image.Scheduler = template.Scheduler
|
||||||
image.Seed = template.Seed
|
image.Seed = template.Seed
|
||||||
|
Reference in New Issue
Block a user