Views
No views yet

diffusers1from diffusers import StableDiffusionPipeline
2import torch
3
4# Load model from Hugging Face
5model_id = "NNNan/UniEM-Gen"
6pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
7pipe = pipe.to("cuda")
8
9# Example prompt, sampled from UniEM-3M.
10prompt = "SEM of Ceramic Powder: A mix of plate-like and rod-shaped particles. nanostructured. high density. densely packed and agglomerated. Multilayer. Wide range of particle sizes. Grayscale particles on a dark background."
11
12# Generate image
13image = pipe(prompt).images[0]
14
15# Save or display
16image.save("generated_em.png")
17image.show()1<microscopy_type> of <subject>: <morphology>. <surface_texture>. <particle_density>. <distribution>. <layering>. <pixel_size_profile>. <color_profile>.
2"💬 Replace each <...> placeholder with a real value from the corresponding category."1# Sampled attributes from UniEM-3M
2from huggingface_hub import hf_hub_download
3import json
4import random
5
6# Download the attribute_values.json file from the repo
7json_path = hf_hub_download(
8 repo_id="NNNan/UniEM-Gen",
9 filename="attribute_values.json"
10)
11
12# Load the attribute values
13with open(json_path, "r", encoding="utf-8") as f:
14 attribute_values = json.load(f)
15
16# Generate a random description
17template = "{microscopy_type} of {subject}: {morphology}. {surface_texture}. {particle_density}. {distribution}. {layering}. {pixel_size_profile}. {color_profile}."
18sampled = {k: random.choice(list(v)) for k, v in attribute_values.items()}
19prompt = template.format(**sampled)
20print(prompt)1@misc{wang2025uniem3muniversalelectronmicrograph,
2 title={UniEM-3M: A Universal Electron Micrograph Dataset for Microstructural Segmentation and Generation},
3 author={Nan wang and Zhiyi Xia and Yiming Li and Shi Tang and Zuxin Fan and Xi Fang and Haoyi Tao and Xiaochen Cai and Guolin Ke and Linfeng Zhang and Yanhui Hong},
4 year={2025},
5 eprint={2508.16239},
6 archivePrefix={arXiv},
7 primaryClass={cs.CV},
8 url={https://arxiv.org/abs/2508.16239},
9}