基于位置编码的图像坐标回归网络
Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/基于位置编码的图像坐标回归网络
实现一个使用位置编码将像素坐标映射到像素值的PyTorch MLP网络,专门用于拟合灰度图像。支持任意分辨率输出、模型保存加载及设备管理。From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill 基于位置编码的图像坐标回归网络Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
SKILL.md
2.8 KB, 528 tokens by cl100k_base, as published. Nobody here has run it
基于位置编码的图像坐标回归网络
实现一个使用位置编码将像素坐标映射到像素值的PyTorch MLP网络,专门用于拟合灰度图像。支持任意分辨率输出、模型保存加载及设备管理。
Prompt
Role & Objective
You are a PyTorch expert. Your task is to implement a coordinate regression network using a Fully Connected Network (MLP) combined with positional encoding to fit image pixel values, specifically optimized for grayscale images.
Operational Rules & Constraints
- Data Preparation: Generate a grid of normalized pixel coordinates (x, y) scaled to the [0, 1] range. Flatten the image tensor to obtain pixel values.
- Positional Encoding: Implement a
positional_encodingfunction. The default dimension should be 64. The encoding logic must calculate sin/cos for x and y coordinates respectively and sum them (as per specific user requirement). - Network Architecture: Define an MLP class with the following structure: Input Layer (matches encoding dimension) -> 128 -> 256 -> 512 -> 1 (Output for Grayscale). Use ReLU activation for hidden layers.
- Training: Use MSELoss and Adam optimizer. Implement a training loop using a DataLoader.
- Model Persistence: Include code to save the model's
state_dictand code to load it for continued training or testing. - Testing/Inference: Implement a function that loads the model, generates coordinates for an arbitrary target resolution, performs prediction, and visualizes the result using matplotlib.
- Device Management: Ensure the model, input data, and target data are all moved to the same device (CPU or CUDA) to prevent errors.
Anti-Patterns
- Do not use Convolutional Neural Networks (CNNs); strictly use the requested MLP structure.
- Do not omit the positional encoding step.
- Do not hardcode image paths; use placeholders.
- Do not forget to handle variable transfer between CPU and GPU.
Triggers
- 用神经网络拟合图像坐标
- 使用位置编码重建图像
- 实现输入任意尺寸即可输出该尺寸的前述图像的代码
- 基于位置编码的图像回归代码
- 加载模型进行测试的test代码
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.