MCPcopy Create free account
hub / github.com/axodox/axodox-machinelearning / TEST_METHOD

Function TEST_METHOD

Axodox.MachineLearning.Test/ControlNetTest.cpp:17–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15 TEST_CLASS(ControlNetTest)
16 {
17 TEST_METHOD(TestControlNet)
18 {
19 StableDiffusionDirectorySessionParameters sessionParameters{ lib_folder() / "../../../models/stable_diffusion" };
20
21 ControlNetOptions options{};
22
23 //Create text embedding
24 {
25 TextEmbedder textEmbedder(sessionParameters);
26 auto positiveEmbedding = textEmbedder.ProcessPrompt("a clean bedroom");
27 auto negativeEmbedding = textEmbedder.ProcessPrompt("blurry, render");
28
29 options.TextEmbeddings.Tensor = negativeEmbedding.Concat(positiveEmbedding);
30 options.TextEmbeddings.Weights = { -1.f, 1.f };
31 }
32
33 //Load conditioning input
34 {
35 auto imagePath = (lib_folder() / "..\\..\\..\\inputs\\depth.png").lexically_normal();
36 auto imageData = read_file(imagePath);
37 auto imageTexture = TextureData::FromBuffer(imageData);
38
39 options.ConditionInput = Tensor::FromTextureData(imageTexture, ColorNormalization::LinearZeroToOne);
40 }
41
42 //Run ControlNet
43 Tensor image;
44 {
45 auto controlnetParameters = OnnxSessionParameters::Create(lib_folder() / "../../../models/controlnet", OnnxExecutorType::Dml);
46 ControlNetInferer controlNet{ controlnetParameters, sessionParameters };
47
48 image = controlNet.RunInference(options);
49 }
50
51 //Decode VAE
52 {
53 VaeDecoder vaeDecoder{ sessionParameters };
54
55 image = vaeDecoder.DecodeVae(image);
56 }
57
58 //Save result
59 {
60 auto imageTexture = image.ToTextureData(ColorNormalization::LinearPlusMinusOne);
61 auto imageBuffer = imageTexture[0].ToBuffer();
62 write_file(lib_folder() / "controlnet.png", imageBuffer);
63 }
64 }
65 };
66}

Callers

nothing calls this directly

Calls 5

ProcessPromptMethod · 0.80
DecodeVaeMethod · 0.80
ToTextureDataMethod · 0.80
ConcatMethod · 0.45
RunInferenceMethod · 0.45

Tested by

no test coverage detected