Skip to content
hyperpolymathPublic

Latest commit

 

History

238 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

VAE Dataset Normalizer

License: PMPL-1.0 :toc: macro :toclevels: 3 :icons: font :source-highlighter: rouge

Normalize VAE-decoded image datasets for training AI artifact detection models, with an Isabelle/HOL theory of the split properties (not yet machine-checked) and RSR (Rhodium Standard Repository) compliance.

Overview

The VAE Dataset Normalizer prepares VAE-decoded image datasets for machine learning research. It provides data splits with SHAKE256 integrity checksums, an Isabelle/HOL theory of split properties over an abstract model (not yet machine-checked; see Formal Verification), and contrastive learning models to detect VAE artifacts.

This project is fully compliant with the Rhodium Standard Repository (RSR) specification, ensuring reproducibility, security, and accountability.

Features

  • SHAKE256 (d=256) cryptographic checksums for data integrity (FIPS 202)

  • Train/Test/Val/Calibration splits (70/15/10/5) - both random and stratified

  • Dublin Core metadata via CUE configuration language

  • Nickel schema for flexible configuration

  • Isabelle/HOL theory of split properties over an abstract model (not yet machine-checked; see Formal Verification)

  • Julia/Flux.jl utilities for training integration

  • Contrastive learning model for VAE artifact detection

  • Diff-based compression reducing storage by ~50%

Installation

Prerequisites

Required
  • Rust 1.70+ with Cargo

Optional
  • CUE - metadata validation

  • Nickel - configuration

  • Julia - training utilities

  • Isabelle - to check the split theory

  • just - modern task runner

  • Podman - container runtime (never Docker)

Build

# Using Just (recommended)
just build

# Using Nix
nix build

# Direct Cargo
cargo build --release

Usage

Normalize a Dataset

# Full normalization with checksums
vae-normalizer normalize -d /path/to/dataset -o /path/to/output

# Fast mode (skip checksums)
vae-normalizer normalize -d /path/to/dataset -o /path/to/output --skip-checksums

# Custom seed and strata
vae-normalizer normalize -d /path/to/dataset -o /path/to/output --seed 12345 --strata 8

Verify Output

# Basic verification
vae-normalizer verify -o /path/to/output

# With checksum verification
vae-normalizer verify -o /path/to/output --checksums -d /path/to/dataset

Show Statistics

# Text format
vae-normalizer stats -o /path/to/output

# JSON format
vae-normalizer stats -o /path/to/output --format json

Compute File Hash

vae-normalizer hash /path/to/image.png

Compress Dataset (Diff Format)

Reduce storage by ~50% by storing VAE images as diffs from originals:

# Compress dataset (creates Original/ + Diff/ structure)
vae-normalizer compress -d /path/to/dataset -o /path/to/compressed

# Decompress (reconstruct full VAE/ directory)
vae-normalizer decompress -d /path/to/compressed -o /path/to/reconstructed-vae

# Reconstruct single image
vae-normalizer reconstruct -o /path/to/original.png -d /path/to/diff.png -o output.png

The diff encoding uses: diff = VAE - Original + 128 (offset for signed values).
Reconstruction: VAE = Original + Diff - 128.

Train Contrastive Model

# Setup Julia dependencies
just julia-setup

# Train VAE artifact detector
just train /path/to/dataset output 50 32

# Train on compressed dataset
just train-compressed /path/to/compressed output 50

# Evaluate model
just evaluate output/vae_classifier.bson /path/to/dataset

Output Structure

output/
├── splits/
│   ├── random_train.txt
│   ├── random_test.txt
│   ├── random_val.txt
│   ├── random_calibration.txt
│   ├── stratified_train.txt
│   ├── stratified_test.txt
│   ├── stratified_val.txt
│   └── stratified_calibration.txt
├── manifest.csv
└── metadata.cue

Dataset Structure

Standard Format

Expected input:

dataset/
├── Original/
│   ├── image001.png
│   ├── image002.png
│   └── ...
└── VAE/
    ├── image001.png
    ├── image002.png
    └── ...

Image files are paired by filename stem (e.g., Original/foo.png pairs with VAE/foo.png).

Compressed Diff Format

After running compress, the dataset uses diff encoding:

compressed/
├── Original/
│   ├── image001.png
│   └── ...
└── Diff/
    ├── image001.png  # Encodes (VAE - Original + 128)
    └── ...

Diff images compress well (~50% smaller) because most pixels cluster near 128 (gray) when VAE and original are similar.

Formal Verification

Status: argued (standards 3-practice/PROOF-POLICY.adoc §5). The theory has not been machine-checked. No workflow runs Isabelle, and the repository has no Isabelle ROOT file, so the build command below cannot find the session yet.

VAEDataset_Splits.thy states lemmas about an abstract split assignment, a function from image ids to an optional split. It is not connected to the Rust code: nothing in it models assign_split_by_index or partition_pairs in src/lib.rs. What each lemma states:

  1. Disjointness (disjoint_from_function): a function-based assignment puts each image in at most one split. This holds for every function.

  2. Partition (split_partition): if every image in a finite set is assigned, the set’s size is the sum of the split sizes. Exhaustiveness is a hypothesis.

  3. Ratios (ratio_correctness): the four split fractions sum to 1. The 1% tolerances are hypotheses; nothing proves the split sizes meet them, and with integer floors they do not for small datasets (assign_split_by_index gives 7/1/1/1 for 10 items, so Test is 10% against a 15% target).

  4. Bijection (bijection_preserved): if the original and VAE images are in bijection, their counts agree. The bijection is a hypothesis.

  5. Stratification (stratified_maintains_ratio) restates its hypothesis.

  6. Checksums: the shake256 locale assumes only determinism and a 32-byte length, with no collision resistance. It proves nothing about bit flips or tampering.

Planned: a ROOT file and a CI job that runs the build, and a model of the Rust split function so that the lemmas say something about the code.

To check the theory (once a ROOT file for the session exists):

isabelle build -d . -b VAEDataset_Splits

Julia Integration

Standard Dataset

include("julia_utils.jl")
using .VAEDatasetUtils

# Load training split
dataset = VAEDetectorDataset(
    "output/splits/random_train.txt",
    "output/manifest.csv",
    "/path/to/dataset"
)

# Create data loader
loader = DataLoader(dataset, batch_size=32, shuffle=true)

# Train with Flux.jl
for (x, y) in loader
    # x: batch of images
    # y: labels (0=original, 1=VAE)
end

Compressed Dataset

include("julia_utils.jl")
using .VAEDatasetUtils

# Load compressed dataset (VAE images reconstructed on-the-fly)
dataset = CompressedVAEDataset(
    "output/splits/random_train.txt",
    "/path/to/compressed/Original",
    "/path/to/compressed/Diff"
)

# Same API as standard dataset
loader = DataLoader(dataset, batch_size=32, shuffle=true)

for (x, y) in loader
    # VAE images are reconstructed automatically from diffs
end

Configuration

CUE Schema

Metadata validated against Dublin Core via metadata_schema.cue:

dublin_core: {
    title:       "VAEDecodedImages-SDXL"
    creator:     "Joshua Jewell"
    type:        "Dataset"
    format:      "image/png"
}

Nickel Config

Alternative configuration via config.ncl:

{
  splits.ratios = {
    train = 0.70,
    test = 0.15,
    validation = 0.10,
    calibration = 0.05,
  },
  checksums.algorithm = 'SHAKE256,
  pipeline.vae_model = "SDXL VAE",
}

RSR Compliance

This repository follows the Rhodium Standard Repository (RSR) specification:

Documentation

  • README.adoc, LICENSE.txt, SECURITY.md, CODE_OF_CONDUCT.md

  • CONTRIBUTING.adoc with Tri-Perimeter Contribution Framework (TPCF)

  • GOVERNANCE.adoc, MAINTAINERS.md, FUNDING.yml

  • CHANGELOG.md, ROADMAP.md, REVERSIBILITY.md

Security

  • Memory-safe Rust implementation (no unsafe code)

  • FIPS 202 compliant cryptography (SHAKE256)

  • Chainguard Wolfi container base

  • SPDX headers on all source files

  • Supply chain security (pinned dependencies)

Infrastructure

  • Nix flakes for reproducibility

  • Podman containers (never Docker)

  • Nickel/CUE configuration

  • Justfile task runner

Accountability

  • Mutually Assured Accountability (MAA) framework

  • Provenance chains (.well-known/provenance.json)

  • Git history with DCO sign-off

Run just validate for full RSR compliance verification.

License

This software is licensed under the Palimpsest-MPL-1.0 License.

The Palimpsest-MPL extends MPL-2.0 with provisions for:

  • Ethical use and emotional lineage preservation

  • Quantum-safe cryptographic provenance

  • Attribution and transparent modification history

  • Community benefit and cooperative economics

See palimpsest-license for full details.

Contributing

See CONTRIBUTING.adoc for contribution guidelines.

Security

See SECURITY.md for security policy and vulnerability reporting.

Architecture

See TOPOLOGY.md for a visual architecture map and completion dashboard.

Releases

Sponsor this project

Packages

Used by

Contributors

Languages