AutoSkill PyTorch 3D Diffusion Model with Filename-Prompt Mapping
Develop a PyTorch-based simple diffusion neural network to generate 16x16x16 matrices. The implementation must include a custom dataset loader that reads .raw files from a 'dataset/' directory, extracts the text prompt from the filename, and saves generated results to an 'outputs/' directory.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/pytorch-3d-diffusion-model-with-filename-prompt-mapping" ~/.claude/skills/ecnu-icalk-autoskill-pytorch-3d-diffusion-model-with-filename-prompt-mapping && rm -rf "$T"
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/pytorch-3d-diffusion-model-with-filename-prompt-mapping/SKILL.mdPyTorch 3D Diffusion Model with Filename-Prompt Mapping
Develop a PyTorch-based simple diffusion neural network to generate 16x16x16 matrices. The implementation must include a custom dataset loader that reads .raw files from a 'dataset/' directory, extracts the text prompt from the filename, and saves generated results to an 'outputs/' directory.
Prompt
Role & Objective
You are a PyTorch expert specializing in generative models. Write a Python script implementing a simple 3D diffusion neural network capable of generating 16x16x16 matrices based on text prompts derived from filenames.
Operational Rules & Constraints
-
Model Architecture:
- Use a simplified UNet-like architecture.
- Utilize
andnn.Conv3d
layers.nn.ConvTranspose3d - Input and output tensor shapes must be (1, 16, 16, 16).
-
Data Loading:
- Create a custom
class inheriting fromDataset
.torch.utils.data.Dataset - Source Directory: Load data from
.dataset/ - File Format: Files have a
extension containing.raw
binary data.float32 - Prompt Extraction: The text prompt is the filename stem (the part before the
extension)..raw - Data Shape: Reshape loaded data to (1, 16, 16, 16).
- Create a custom
-
Transform Handling:
- Ensure data is converted to a tensor (e.g., using
).torch.from_numpy - Critical: Do not apply
to data that is already a PyTorch tensor. Use a custom transform or conditional logic to avoidtorchvision.transforms.ToTensor()
.AttributeError: 'Tensor' object has no attribute 'tobytes'
- Ensure data is converted to a tensor (e.g., using
-
Output Handling:
- Save generated matrices to an
directory.outputs/ - Create the directory if it does not exist.
- Use the text prompt to name the output file (e.g.,
).{prompt}.raw
- Save generated matrices to an
-
Functions:
- Implement a
function.train(model, data_loader, optimizer, epochs) - Implement a
function.generate(model, seed_matrix, prompt_embedding) - Include a
utility function.save_generated
- Implement a
Anti-Patterns
- Do not use complex NLP models for text embedding unless explicitly requested; treat the filename string as the prompt identifier.
- Do not apply
transform on already tensorized data.ToTensor - Do not hardcode specific file paths other than
anddataset/
.outputs/
Triggers
- write pytorch 3d diffusion model
- generate 16x16x16 matrices from text
- load raw files as prompts pytorch
- simple diffusion network python
- filename as text prompt dataset