Documentation
¶
Overview ¶
Package fooocus implements reading and writing Fooocus metadata (image generation parameters).
To read metadata, use the Fooocus metadata extractor:
path := "testdata/sample.jpg" image, err := image.NewContextFromFile(path) extractor := NewFooocusMetadataExtractor() meta, err := extractor.Decode(*image) fmt.Println(meta.Version) // prints "Fooocus v2.5.5"
This supports reading from both the embedded metadata or the private log file, if available as "log.html" in the same folder as the image files.
To write metadata into a PNG, use the Fooocus metadata writer:
meta := &Metadata{}
target, err := os.OpenFile("out.png", os.O_CREATE|os.O_WRONLY, 0644)
writer := NewFooocusMetadataWriter()
writer.Write(target, meta)
Index ¶
- Constants
- func NewFooocusMetadataExtractor() m.Reader[Metadata]
- func NewFooocusMetadataWriter() m.Writer[Metadata]
- func ParsePrivateLog(filePath string) (map[string]Metadata, error)
- type AdmGuidance
- type FooocusMetadataExtractor
- type FooocusMetadataWriter
- type FreeU
- type Lora
- type LoraCombined
- type Metadata
- type MetadataScheme
- type MetadataV21
- type MetadataV22
- type MetadataV23
- type MetadataVersion
- type Parameters
- func (m Parameters) CreatedTime() time.Time
- func (m Parameters) LoRAs() []types.Lora
- func (m Parameters) Model() string
- func (m Parameters) NegativePrompt() string
- func (m Parameters) PositivePrompt() string
- func (m Parameters) Raw() interface{}
- func (m Parameters) Seed() string
- func (m Parameters) Version() string
- type Resolution
- type Styles
- type Tuple
- type Version
Constants ¶
const (
Software = "Fooocus"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AdmGuidance ¶
func AdmGuidanceOf ¶
func AdmGuidanceOf(p float32, n float32, e float32) *AdmGuidance
type FooocusMetadataExtractor ¶
type FooocusMetadataExtractor struct {
*m.FileMetadataExtractor
}
FooocusMetadataExtractor can decode embedded Fooocus metadata from an image file, or external metadata from the Fooocus private log.
func (FooocusMetadataExtractor) Decode ¶
func (e FooocusMetadataExtractor) Decode(file m.ImageMetadataContext) (meta Metadata, err error)
func (FooocusMetadataExtractor) Extract ¶
func (e FooocusMetadataExtractor) Extract(file m.ImageMetadataContext) (m.StructuredMetadata, error)
type FooocusMetadataWriter ¶
type FooocusMetadataWriter struct {
*m.PngMetadataWriter
}
FooocusMetadataWriter can embed Fooocus metadata into a PNG image file.
type Lora ¶
Encoded as nested list of format: list [string, float32, string] (lora name, lora weight, lora hash)
func (Lora) MarshalJSON ¶
func (*Lora) UnmarshalJSON ¶
type LoraCombined ¶
type LoraCombined Lora
String of format "<name> : <weight>"
func (LoraCombined) MarshalJSON ¶
func (l LoraCombined) MarshalJSON() ([]byte, error)
func (*LoraCombined) UnmarshalJSON ¶
func (l *LoraCombined) UnmarshalJSON(p []byte) error
type Metadata ¶
type Metadata = MetadataV23
func ConvertV21ToV23 ¶
func ConvertV21ToV23(v21 *MetadataV21) (v23 Metadata)
type MetadataScheme ¶
type MetadataScheme uint8
Fooocus suports encoding metadata with one of two schemes:
- the native JSON scheme
- the AUTOMATIC1111 plaintext format for compatibility with Stable Diffusion web UI
const ( Fooocus MetadataScheme = iota // fooocus A1111 // a1111 )
func (MetadataScheme) String ¶
func (i MetadataScheme) String() string
type MetadataV21 ¶
type MetadataV21 struct {
AdmGuidance *AdmGuidance `json:"ADM Guidance"` // string: python tuple (p: float, n: float, e: float)
BaseModel string `json:"Base Model"`
CFGMimicking float32 `json:"CFG Mimicking from TSNR,omitempty"`
ClipSkip uint8 `json:"CLIP Skip,omitempty"`
FooocusV2Expansion string `json:"Fooocus V2 Expansion"`
FreeU *FreeU `json:"FreeU,omitempty"` // string: python tuple (b1: float, b2: float, s1: float, s2: float)
GuidanceScale float32 `json:"Guidance Scale"`
ImageNumber uint `json:"Image Number,omitempty"`
InpaintEngineVersion string `json:"Inpaint Engine Version,omitempty"`
InpaintMode string `json:"Inpaint Mode,omitempty"`
Lora1 *LoraCombined `json:"LoRA 1,omitempty"`
Lora2 *LoraCombined `json:"LoRA 2,omitempty"`
Lora3 *LoraCombined `json:"LoRA 3,omitempty"`
Lora4 *LoraCombined `json:"LoRA 4,omitempty"`
Lora5 *LoraCombined `json:"LoRA 5,omitempty"`
Lora6 *LoraCombined `json:"LoRA 6,omitempty"`
NegativePrompt string `json:"Negative Prompt"`
OverWriteSwitch float32 `json:"Overwrite Switch,omitempty"`
Performance string `json:"Performance"`
Prompt string `json:"Prompt"`
RefinerModel string `json:"Refiner Model"`
RefinerSwapMethod string `json:"Refiner Swap Method,omitempty"`
RefinerSwitch float32 `json:"Refiner Switch"`
Resolution *Resolution `json:"Resolution"` // string: python tuple (width: int, height: int)
Sampler string `json:"Sampler"`
Scheduler string `json:"Scheduler"`
Seed int `json:"Seed"`
Sharpness float32 `json:"Sharpness"`
Steps uint8 `json:"Steps,omitempty"` // TODO: post process default from Performance
Styles Styles `json:"Styles"`
Vae string `json:"VAE,omitempty"`
Version string `json:"Version"`
}
Fooocus legacy metadata schema (json).
This format is only found in the private log HTML file generated by Fooocus v2.1.0 and older.
Reference implementation:
type MetadataV22 ¶
type MetadataV22 struct {
MetadataV23
Seed int `json:"seed"`
MetadataScheme bool `json:"metadata_scheme"`
}
Fooocus v2.2 metadata scheme (json).
This format is found in the private log HTML file generated by Fooocus v2.2.x.
type MetadataV23 ¶
type MetadataV23 struct {
AdaptiveCfg float32 `json:"adaptive_cfg,omitempty"`
AdmGuidance *AdmGuidance `json:"adm_guidance"`
BaseModel string `json:"base_model"`
BaseModelHash string `json:"base_model_hash"`
ClipSkip uint8 `json:"clip_skip"`
CreatedBy string `json:"created_by,omitempty"`
FreeU *FreeU `json:"freeu,omitempty"` // string: python tuple (b1: float, b2: float, s1: float, s2: float)
FullNegativePrompt []string `json:"full_negative_prompt,omitempty"`
FullPrompt []string `json:"full_prompt,omitempty"`
GuidanceScale float32 `json:"guidance_scale"`
ImageNumber uint `json:"image_number,omitempty"`
InpaintEngineVersion string `json:"inpaint_engine_version,omitempty"`
InpaintMode string `json:"inpaint_method,omitempty"`
LoraCombined1 *LoraCombined `json:"lora_combined_1,omitempty"`
LoraCombined2 *LoraCombined `json:"lora_combined_2,omitempty"`
LoraCombined3 *LoraCombined `json:"lora_combined_3,omitempty"`
LoraCombined4 *LoraCombined `json:"lora_combined_4,omitempty"`
LoraCombined5 *LoraCombined `json:"lora_combined_5,omitempty"`
Loras []Lora `json:"loras"`
MetadataScheme string `json:"metadata_scheme"`
NegativePrompt string `json:"negative_prompt"`
Performance string `json:"performance"`
Prompt string `json:"prompt"`
PromptExpansion string `json:"prompt_expansion"`
RefinerModel string `json:"refiner_model,omitempty"`
RefinerModelHash string `json:"refiner_model_hash,omitempty"`
RefinerSwapMethod string `json:"refiner_swap_method,omitempty"`
RefinerSwitch float32 `json:"refiner_switch"`
Resolution *Resolution `json:"resolution"`
Sampler string `json:"sampler"`
Scheduler string `json:"scheduler"`
Seed string `json:"seed"`
Sharpness float32 `json:"sharpness"`
Steps uint8 `json:"steps"`
Styles Styles `json:"styles"`
Vae string `json:"vae"`
Version string `json:"version"`
}
Fooocus v2.3 metadata scheme (json).
Used by Fooocus v2.2 and newer for embedded metadata. Used by Fooocus v2.3 and newer for private log metadata.
Reference implementation:
func ConvertV22ToV23 ¶
func ConvertV22ToV23(v22 *MetadataV22) (v23 MetadataV23)
func (*MetadataV23) UnmarshalJSON ¶
func (m *MetadataV23) UnmarshalJSON(data []byte) error
type MetadataVersion ¶
type MetadataVersion uint8
func (MetadataVersion) String ¶
func (i MetadataVersion) String() string
type Parameters ¶
Adapter that implements the types.GenerationParameters interface on top of Fooocus Metadata.
func (Parameters) CreatedTime ¶
func (m Parameters) CreatedTime() time.Time
func (Parameters) LoRAs ¶
func (m Parameters) LoRAs() []types.Lora
func (Parameters) Model ¶
func (m Parameters) Model() string
func (Parameters) NegativePrompt ¶
func (m Parameters) NegativePrompt() string
func (Parameters) PositivePrompt ¶
func (m Parameters) PositivePrompt() string
func (Parameters) Raw ¶
func (m Parameters) Raw() interface{}
func (Parameters) Seed ¶
func (m Parameters) Seed() string
func (Parameters) Version ¶
func (m Parameters) Version() string
type Resolution ¶
func ResolutionOf ¶
func ResolutionOf(height uint16, width uint16) *Resolution
type Styles ¶
type Styles []string
Styles are encoded within a string using single-quoted values, e.g.: "['Fooocus V2', 'Fooocus Enhance', 'Fooocus Sharp']"
func (Styles) MarshalJSON ¶
func (*Styles) UnmarshalJSON ¶
type Tuple ¶
Tuple is an arbitrary length tuple backed by a slice. It is used to marshal/unmarshal Fooocus' string-encoded tuples.
func (Tuple[T]) MarshalJSON ¶
func (*Tuple[T]) UnmarshalJSON ¶
type Version ¶
type Version struct {
Version string `json:"version"`
MetadataScheme json.RawMessage `json:"metadata_scheme"`
}
func (*Version) MetadataVersion ¶
func (v *Version) MetadataVersion() MetadataVersion