赞
踩
* 反向提示词, 默认 “”
*/
private String negative_prompt;
private List<String> styles;
/\*\*
* 随机数种子 (Seed)
*/
private Integer seed;
private Integer clip_skip;
/\*\*
*
*/
private Integer subseed;
/\*\*
*
*/
private Integer subseed_strength;
/\*\*
* 高度
*/
private Integer seed_resize_from_h;
/\*\*
* 宽度
*/
private Integer seed_resize_from_w;
/\*\*
* 采样方法 (Sampler), 默认 null
*/
private String sampler_name;
/\*\*
* 采样方法 (Sampler) 下标
*/
private String sampler_index;
/\*\*
* 批次数 default: 1
*/
private Integer batch_size;
/\*\*
* 每批的数量 default: 1
*/
private Integer n_iter;
/\*\*
* 迭代步数 (Steps), 默认 50
*/
private Integer steps;
/\*\*
* 提示词引导系数, 默认7
*/
private Double cfg_scale;
/\*\*
* 宽度
*/
private Integer width;
/\*\*
* 高度
*/
private Integer height;
/\*\*
* 面部修复, 默认 false
*/
private Boolean restore_faces;
/\*\*
* 平铺图 默认 false
*/
private Boolean tiling;
/\*\*
* 默认 false
*/
private Boolean do_not_save_samples;
/\*\*
* 默认 false
*/
private Boolean do_not_save_grid;
/\*\*
* 默认 null
*/
private Integer eta;
/\*\*
* 默认 0
*/
private Integer s_min_uncond;
/\*\*
* 默认 0
*/
private Integer s_churn;
/\*\*
* 默认 null
*/
private Integer s_tmax;
/\*\*
* 默认 0
*/
private Integer s_tmin;
/\*\*
* 默认 1
*/
private Integer s_noise;
/\*\*
* 默认 null
*/
private OverrideSettings override_settings;
/\*\*
* 默认 true
*/
private Boolean override_settings_restore_afterwards;
private List<Object> script_args;
/\*\*
* 默认 null
*/
private String script_name;
/\*\*
* 默认 true
*/
private Boolean send_images;
/\*\*
* 默认 false
*/
private Boolean save_images;
/\*\*
* 默认 {}
*/
private AlwaysonScripts alwayson_scripts;
上述重要的参数都标注了注释,基本够用,下面也会给出入参类的构建示例。
OverrideSettings 类:用于指定基础模型和 VAE:
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OverrideSettings {
private String sd_model_checkpoint;
private String sd_vae;
}
AlwaysonScripts 类,其中可以指定 ControlNet:
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 参考:https://zhuanlan.zhihu.com/p/624042359
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AlwaysonScripts {
private ControlNet controlnet;
}
ControlNet 类,其中可以指定多组 Args(一个 Args 是一个 ControlNet)
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ControlNet {
private List args;
}
Args 类,即指定一个 ControlNet 的所有参数:
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 参考:https://github.com/Mikubill/sd-webui-controlnet/wiki/API#integrating-sdapiv12img
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Args {
private boolean enabled;
/**
* PreProcessor 例如:“module”: “lineart_coarse”
*/
private String module;
private String model;
/\*\*
* defaults to 1
*/
private double weight = 1.0;
private String input_image;
private String mask;
private int control_mode = 0;
/\*\*
* enable pixel-perfect preprocessor. defaults to false
*/
private boolean pixel_perfect;
/\*\*
* whether to compensate low GPU memory with processing time. defaults to false
*/
private boolean lowvram;
private int processor_res;
private int threshold_a;
private int threshold_b;
private double guidance_start;
private double guidance_end = 1.0;
StableDiffusionTextToImgResponse 类,即 stable diffusion webui 的响应结构:
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StableDiffusionTextToImgResponse implements Serializable {
/\*\*
* 生成的图片结果 base64
*/
private List images;
/\*\*
* 入参和默认值
*/
private StableDiffusionTextToImg parameters;
/\*\*
* 参数的组合字符串
*/
private String info;
}
### Java 测试调用文生图 API
StableDiffusionTest 类:
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.io.*;
import java.util.*;
@Slf4j
public class StableDiffusionTest1 {
@Test public void testSdApi() throws IOException { StableDiffusionTextToImg body = getArtisticWordStableDiffusionTextToImg(); final List<String> images = callSdApi(body); for (String image : images) { writeBase642ImageFile(image, String.format("./%s.png", UUID.randomUUID().toString().replaceAll("-", ""))); } } public static void writeBase642ImageFile(String image, String fileName) { try (OutputStream outputStream = new FileOutputStream(fileName)) { byte[] imageBytes = Base64.getDecoder().decode(image); ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, bytesRead); } log.info("图片写入成功!"); } catch (IOException e) { e.printStackTrace(); } } private StableDiffusionTextToImg getArtisticWordStableDiffusionTextToImg() throws IOException { final String base64SrcImg = convertImageToBase64("./cat-768x512.png"); Args args1 = Args.builder() .enabled(true) .control\_mode(0) .guidance\_start(0) .guidance\_end(0.5) .weight(0.3) .pixel\_perfect(true) .resize\_mode(1) .model("control\_v11p\_sd15\_softedge [a8575a2a]") .module("softedge\_pidinet") .input\_image(base64SrcImg) .build(); Args args2 = Args.builder() .enabled(true) .control\_mode(0) .guidance\_start(0) .guidance\_end(0.5) .weight(0.75) .pixel\_perfect(true) .resize\_mode(1) .model("control\_v11f1p\_sd15\_depth [cfd03158]") .module("depth\_midas") .input\_image(base64SrcImg) .build(); String vae = "vae-ft-mse-840000-ema-pruned.safetensors"; StableDiffusionTextToImg body = StableDiffusionTextToImg.builder().sampler\_name("") .prompt("(cake:1.8),( 3D:1.8),( shadow:1.8),(best quality:1.25),( masterpiece:1.25), (ultra high res:1.25), (no human:1.3),<lora:tachi-e:1>,(white background:2)") .negative\_prompt("EasyNegative, paintings, sketches, (worst quality:2), (low quality:2), (normal quality:2), lowres, normal quality, ((monochrome)), ((grayscale)), skin spots, acnes, skin blemishes, age spot, glans,extra fingers,fewer fingers,strange fingers,bad hand,backlight, (worst quality, low quality:1.4), watermark, logo, bad anatomy,lace,rabbit,back,") .sampler\_index("DPM++ SDE Karras") .seed(-1) .width(768) .height(512) .restore\_faces(false) .tiling(false) .clip\_skip(2) .batch\_size(4) .script\_args(new ArrayList<>()) .alwayson\_scripts(AlwaysonScripts.builder().controlnet(ControlNet.builder() .args(Lists.newArrayList(args1, args2)).build()).build()) .steps(28).override\_settings(OverrideSettings.builder() .sd\_model\_checkpoint("chosenMix\_chosenMix.ckpt [dd0aacadb6]") .sd\_vae(vae) .build()) .cfg\_scale(7.0).build(); return body; } public static String convertImageToBase64(String imagePath) throws IOException { File file = new File(imagePath); FileInputStream fileInputStream = new FileInputStream(file); byte[] imageData = new byte[(int) file.length()]; fileInputStream.read(imageData); fileInputStream.close(); return Base64.getEncoder().encodeToString(imageData); } private List<String> callSdApi(StableDiffusionTextToImg body) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION\_JSON); HttpEntity<StableDiffusionTextToImg> requestEntity = new HttpEntity<>(body, headers); ResponseEntity<JSONObject> entity = restTemplate.postForEntity("http://sd.cn/sdapi/v1/txt2img", requestEntity, JSONObject.class); final StableDiffusionTextToImgResponse stableDiffusionTextToImgResponse = handleResponse(entity); final List<String> images = stableDiffusionTextToImgResponse.getImages(); if (CollectionUtils.isEmpty(images)) { log.info("empty images"); return Lists.newArrayList(); } return images; } private StableDiffusionTextToImgResponse handleResponse(ResponseEntity<JSONObject> response) { if (Objects.isNull(response) || !response.getStatusCode().is2xxSuccessful()) { log.warn("call stable diffusion api status code: {}", JSONObject.toJSONString(response)); } final JSONObject body = response.getBody();
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Web前端开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上前端开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024c (备注前端)
正式学习前端大概 3 年多了,很早就想整理这个书单了,因为常常会有朋友问,前端该如何学习,学习前端该看哪些书,我就讲讲我学习的道路中看的一些书,虽然整理的书不多,但是每一本都是那种看一本就秒不绝口的感觉。
以下大部分是我看过的,或者说身边的人推荐的书籍,每一本我都有些相关的推荐语,如果你有看到更好的书欢迎推荐呀。
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
义、实战项目、讲解视频,并且后续会持续更新**
如果你觉得这些内容对你有帮助,可以添加V获取:vip1024c (备注前端)
[外链图片转存中…(img-JxkJs00j-1712864635362)]
正式学习前端大概 3 年多了,很早就想整理这个书单了,因为常常会有朋友问,前端该如何学习,学习前端该看哪些书,我就讲讲我学习的道路中看的一些书,虽然整理的书不多,但是每一本都是那种看一本就秒不绝口的感觉。
以下大部分是我看过的,或者说身边的人推荐的书籍,每一本我都有些相关的推荐语,如果你有看到更好的书欢迎推荐呀。
[外链图片转存中…(img-ligSYq3n-1712864635362)]
一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
[外链图片转存中…(img-LM88iaB5-1712864635363)]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。