---
title: mocode-mini-gguf
canonical_url: "https://www.modelscope.cn/models/gzwebsj/mocode-mini-gguf"
md_url: "https://www.modelscope.cn/models/gzwebsj/mocode-mini-gguf.md"
repository: gzwebsj/mocode-mini-gguf
last_updated: 2026-07-17
library_name:
  - pytorch
  - gguf
downloads: 5
stars: 0
tags:
  - gguf
---

# mocode-mini-gguf

> mocode-mini-gguf - gzwebsj 在 ModelScope 开源的模型。Mocode深度学习统一模型 - 集成4个图像处理子模型(GOPRO去模糊/VINS编辑分类/NOOB2EDIT动漫CG分类/VFI视频帧插值)

- **Repository**: gzwebsj/mocode-mini-gguf
- **Tags**: gguf
- **Downloads**: 5
- **Stars**: 0
- **Last updated**: 2026-07-17

Source: https://www.modelscope.cn/models/gzwebsj/mocode-mini-gguf

---

# Mocode Deep Learning Unified Model

Mocode 深度学习统一模型 - 集成 4 个图像处理子模型，采用 GGUF 格式存储。

## 模型概览

| 属性 | 值 |
|------|-----|
| **模型名称** | Mocode-DeepLearning-Unified |
| **格式** | GGUF v3 |
| **子模型数** | 4 |
| **张量总数** | 336 |
| **参数总量** | 16.46M (16,464,238) |
| **文件大小** | 62.83 MB |
| **精度** | F32 (float32) |
| **框架** | Mocode DeepLearningEngine (PyTorch) |
| **License** | Apache-2.0 |

---

## 子模型列表

### 1. GOPRO 图像去模糊 (GOPRO-Deblur-UNet)

**任务**: 图像去运动模糊 (Image Deblurring)

**数据集**: [iic/GOPRO](https://modelscope.cn/datasets/iic/GOPRO)
- 3214 张 1280×720 PNG 图像（训练使用合成数据：800 训练 + 200 测试，128×128）

**架构**: U-Net (编码器-解码器 + 跳跃连接)

| 组件 | 规格 |
|------|------|
| 输入通道 | 3 (RGB) |
| 输出通道 | 3 (RGB) |
| 基础滤波器 | 32 |
| 编码器层数 | 4 (32→64→128→256) |
| 瓶颈层 | 512 通道 |
| 解码器层数 | 4 (256→128→64→32) |
| 输出卷积 | 1×1 Conv |
| 激活函数 | ReLU |
| 参数量 | 7.77M |

**训练配置**:

| 配置项 | 值 |
|--------|-----|
| 优化器 | Adam |
| 学习率 | 0.001 |
| 损失函数 | MSE |
| LR 调度器 | Cosine Annealing |
| Batch Size | 8 |
| Epochs | 30 |
| Weight Decay | 1e-4 |
| 训练设备 | CUDA GPU |
| 训练时间 | 3.8 分钟 |

**性能指标**:

| 指标 | 值 |
|------|-----|
| 最佳 PSNR | 28.46 dB |
| 最佳 epoch | 27 |
| 测试损失 (MSE) | 0.001427 |
| 初始 PSNR | 22.38 dB |
| PSNR 提升 | +6.08 dB |

**张量命名空间前缀**: `gopro.` (共 136 个张量)

---

### 2. VINS 图像编辑分类 (VINS-Edit-Classification-CNN)

**任务**: 超高分辨率图像编辑类型分类 (13 类)

**数据集**: [vivo/VINS-120K](https://modelscope.cn/datasets/vivo/VINS-120K)
- 120K 三元组，13 种编辑类型（训练使用合成数据：1495 训练 + 494 测试，64×64）

**13 种编辑类型**:
style_transfer, color_grade, character_add, character_remove, background_swap,
face_modify, outfit_change, lighting_relight, season_shift, weather_effect,
time_of_day, artistic_filter, detail_enhance

**架构**: CNN (4 个卷积块 + 全局平均池化 + 2 层全连接)

| 组件 | 规格 |
|------|------|
| 输入尺寸 | 64×64×3 (RGB) |
| 输出类别 | 13 |
| Block 1 | Conv2d(3→32, 3×3) + BN + MaxPool(2×2) |
| Block 2 | Conv2d(32→64, 3×3) + BN + MaxPool(2×2) |
| Block 3 | Conv2d(64→128, 3×3) + BN + MaxPool(2×2) |
| Block 4 | Conv2d(128→256, 3×3) + BN + MaxPool(2×2) |
| GAP | AdaptiveAvgPool2d(1×1) |
| FC1 | Linear(256→256) + ReLU |
| FC2 | Linear(256→13) + Linear |
| 参数量 | 0.46M |

**训练配置**:

| 配置项 | 值 |
|--------|-----|
| 优化器 | Adam |
| 学习率 | 0.001 |
| 损失函数 | CrossEntropyLoss |
| LR 调度器 | Cosine Annealing |
| Batch Size | 16 |
| Epochs | 40 (早停于 11) |
| Early Stop | 10 epochs |
| Weight Decay | 1e-4 |
| 训练设备 | CUDA GPU |
| 训练时间 | 11.7 秒 |

**性能指标**:

| 指标 | 值 |
|------|-----|
| 最佳准确率 | 100% |
| 最佳 epoch | 1 |
| 早停 epoch | 11 |

**张量命名空间前缀**: `vins.` (共 32 个张量)

---

### 3. NOOB2EDIT 动漫CG编辑分类 (NOOB2EDIT-GameCG-Classification-CNN)

**任务**: 动漫游戏 CG 编辑类型分类 (15 类)

**数据集**: [niangao233/NOOB2EDIT_GAMECG_15M](https://modelscope.cn/datasets/niangao233/NOOB2EDIT_GAMECG_15M)
- 1600 万张动漫游戏 CG（AVIF 格式），170 万+ 聚类组（训练使用合成数据：1500 训练 + 495 测试，64×64）

**15 种编辑类型**:
style_transfer, color_grade, character_add, character_remove, background_swap,
face_modify, outfit_change, lighting_relight, season_shift, weather_effect,
time_of_day, artistic_filter, detail_enhance, composition_crop, semantic_edit

**架构**: CNN (4 个卷积块 + 全局平均池化 + 2 层全连接)

| 组件 | 规格 |
|------|------|
| 输入尺寸 | 64×64×3 (RGB) |
| 输出类别 | 15 |
| Block 1 | Conv2d(3→32, 3×3) + BN + MaxPool(2×2) |
| Block 2 | Conv2d(32→64, 3×3) + BN + MaxPool(2×2) |
| Block 3 | Conv2d(64→128, 3×3) + BN + MaxPool(2×2) |
| Block 4 | Conv2d(128→256, 3×3) + BN + MaxPool(2×2) |
| GAP | AdaptiveAvgPool2d(1×1) |
| FC1 | Linear(256→256) + ReLU |
| FC2 | Linear(256→15) + Linear |
| 参数量 | 0.46M |

**训练配置**:

| 配置项 | 值 |
|--------|-----|
| 优化器 | Adam |
| 学习率 | 0.001 |
| 损失函数 | CrossEntropyLoss |
| LR 调度器 | Cosine Annealing |
| Batch Size | 16 |
| Epochs | 40 (早停于 11) |
| Early Stop | 10 epochs |
| Weight Decay | 1e-4 |
| 训练设备 | CUDA GPU |
| 训练时间 | 10.6 秒 |

**性能指标**:

| 指标 | 值 |
|------|-----|
| 最佳准确率 | 100% |
| 最佳 epoch | 1 |
| 早停 epoch | 11 |

**张量命名空间前缀**: `noob2edit.` (共 32 个张量)

---

### 4. VFI 视频帧插值 (VFI-FrameInterpolation-UNet)

**任务**: 视频帧插值 (Video Frame Interpolation) - 从两边界帧预测中间帧

**数据集**: [aojie1997/cv_video-frame-interpolation_ValidationDataset](https://modelscope.cn/datasets/aojie1997/cv_video-frame-interpolation_ValidationDataset)
- 真实数据：ucf_101(100) + middlebury(10) + davis(2849) = 2959 组
- 训练使用: 800 训练 + 200 测试，128×128
- 每组: 4 帧输入 (Input1-4) + 1 帧 GT (Output)

**架构**: U-Net (编码器-解码器 + 跳跃连接)

| 组件 | 规格 |
|------|------|
| 输入通道 | 6 (Input1 RGB + Input4 RGB 拼接) |
| 输出通道 | 3 (Output 中间帧 RGB) |
| 基础滤波器 | 32 |
| 编码器层数 | 4 (32→64→128→256) |
| 瓶颈层 | 512 通道 |
| 解码器层数 | 4 (256→128→64→32) |
| 输出卷积 | 1×1 Conv |
| 激活函数 | ReLU |
| 参数量 | 7.77M |

**训练配置**:

| 配置项 | 值 |
|--------|-----|
| 优化器 | Adam |
| 学习率 | 0.001 |
| 损失函数 | MSE |
| LR 调度器 | Cosine Annealing |
| Batch Size | 8 |
| Epochs | 30 |
| Weight Decay | 1e-4 |
| 训练设备 | CUDA GPU |
| 训练时间 | 3.8 分钟 |

**性能指标**:

| 指标 | 值 |
|------|-----|
| 最佳 PSNR | 19.42 dB |
| 最佳 epoch | 29 |
| 测试损失 (MSE) | 0.011423 |
| 初始 PSNR | 18.60 dB |
| PSNR 提升 | +0.82 dB |

**张量命名空间前缀**: `vfi.` (共 136 个张量)

---

## GGUF 格式详情

### 文件结构

```
GGUF Header
  ├── Magic (4B): 0x46554747
  ├── Version (4B): 3
  ├── Tensor Count (8B): 336
  ├── Metadata Count (8B): 57
  ├── Metadata KV Pairs
  ├── Tensor Info (name, dims, type, offset)
  ├── 32-byte Alignment Padding
  └── Tensor Data (F32, 32-byte aligned)
```

### 全局元数据

| Key | Value |
|-----|-------|
| `general.name` | Mocode-DeepLearning-Unified |
| `general.architecture` | multi_model_ensemble |
| `general.version` | 1.0.0 |
| `general.framework` | Mocode |
| `general.format` | GGUF |
| `general.submodel_count` | 4 |
| `general.total_params` | 16464238 |
| `general.total_tensors` | 336 |
| `general.submodels` | [4 个子模型名称列表] |
| `general.tasks` | [4 个子模型任务列表] |
| `general.architectures` | [4 个子模型架构列表] |

### 子模型元数据

每个子模型的元数据使用 `submodel.{key}.` 前缀组织：

| Key 模式 | 说明 |
|----------|------|
| `submodel.{key}.name` | 子模型名称 |
| `submodel.{key}.task` | 子模型任务 |
| `submodel.{key}.architecture` | 子模型架构 |
| `submodel.{key}.description` | 子模型描述 |
| `submodel.{key}.n_tensors` | 子模型张量数 |
| `submodel.{key}.n_params` | 子模型参数量 |
| `submodel.{key}.general.*` | 原始模型通用元数据 |

### 张量命名规范

每个子模型的所有权重张量使用子模型 key 作为命名空间前缀：

- `gopro.enc1.0.weight` - GOPRO 第一层编码卷积权重
- `vins.layers.0.layer.weight` - VINS 第一层卷积权重
- `noob2edit.layers.15.layer.0.weight` - NOOB2EDIT 分类头权重
- `vfi.out_conv.weight` - VFI 输出卷积权重

---

## 使用方式

### 加载模型 (Python)

```python
import numpy as np
import struct

GGUF_MAGIC = 0x46554747
GGML_TYPE_F32 = 0

def read_gguf_string(f):
    length = struct.unpack('<Q', f.read(8))[0]
    return f.read(length).decode('utf-8')

def load_gguf_tensors(file_path):
    """加载GGUF文件中的所有权重张量"""
    with open(file_path, 'rb') as f:
        # 读取头部
        magic = struct.unpack('<I', f.read(4))[0]
        assert magic == GGUF_MAGIC, "Invalid GGUF magic"
        version = struct.unpack('<I', f.read(4))[0]
        tensor_count = struct.unpack('<Q', f.read(8))[0]
        metadata_count = struct.unpack('<Q', f.read(8))[0]
        
        # 跳过元数据
        for _ in range(metadata_count):
            read_gguf_string(f)  # key
            vtype = struct.unpack('<I', f.read(4))[0]
            # 跳过 value（简化处理）
            if vtype == 9:  # ARRAY
                struct.unpack('<I', f.read(4))  # elem_type
                n = struct.unpack('<Q', f.read(8))[0]
                for _ in range(n):
                    struct.unpack('<Q', f.read(8))  # 粗略跳过
            else:
                f.read(8)  # 粗略跳过
        
        # 读取张量信息
        tensor_infos = []
        for _ in range(tensor_count):
            name = read_gguf_string(f)
            n_dims = struct.unpack('<I', f.read(4))[0]
            dims = [struct.unpack('<Q', f.read(8))[0] for _ in range(n_dims)]
            dims = dims[::-1]  # 反序
            ggml_type = struct.unpack('<I', f.read(4))[0]
            offset = struct.unpack('<Q', f.read(8))[0]
            tensor_infos.append((name, dims, ggml_type, offset))
        
        # 对齐到32字节
        pos = f.tell()
        aligned = (pos + 31) & ~31
        f.seek(aligned)
        data_start = f.tell()
        
        # 读取张量数据
        tensors = {}
        for name, dims, ggml_type, offset in tensor_infos:
            f.seek(data_start + offset)
            shape = tuple(dims)
            n_elements = 1
            for d in shape:
                n_elements *= d
            data = f.read(n_elements * 4)  # F32 = 4 bytes
            tensors[name] = np.frombuffer(data, dtype=np.float32).reshape(shape).copy()
        
        return tensors

# 加载所有子模型权重
all_tensors = load_gguf_tensors('mocode_mini.gguf')

# 提取 GOPRO 子模型权重
gopro_weights = {k.replace('gopro.', ''): v 
                 for k, v in all_tensors.items() 
                 if k.startswith('gopro.')}

# 提取 VFI 子模型权重
vfi_weights = {k.replace('vfi.', ''): v 
               for k, v in all_tensors.items() 
               if k.startswith('vfi.')}
```

### GOPRO 图像去模糊推理 (PyTorch)

```python
import torch
import torch.nn as nn
import numpy as np
from PIL import Image

# 定义与训练一致的 U-Net 架构
class DoubleConv(nn.Module):
    def __init__(self, in_ch, out_ch):
        super().__init__()
        self.conv = nn.Sequential(
            nn.Conv2d(in_ch, out_ch, 3, padding=1),
            nn.ReLU(inplace=True),
            nn.Conv2d(out_ch, out_ch, 3, padding=1),
            nn.ReLU(inplace=True),
        )
    def forward(self, x):
        return self.conv(x)

class UNet(nn.Module):
    def __init__(self, in_ch=3, out_ch=3, base_filters=32):
        super().__init__()
        f = base_filters
        self.enc1 = DoubleConv(in_ch, f)
        self.enc2 = DoubleConv(f, f*2)
        self.enc3 = DoubleConv(f*2, f*4)
        self.enc4 = DoubleConv(f*4, f*8)
        self.pool = nn.MaxPool2d(2)
        self.bottleneck = DoubleConv(f*8, f*16)
        self.upconv4 = nn.ConvTranspose2d(f*16, f*8, 2, stride=2)
        self.dec4 = DoubleConv(f*16, f*8)
        self.upconv3 = nn.ConvTranspose2d(f*8, f*4, 2, stride=2)
        self.dec3 = DoubleConv(f*8, f*4)
        self.upconv2 = nn.ConvTranspose2d(f*4, f*2, 2, stride=2)
        self.dec2 = DoubleConv(f*4, f*2)
        self.upconv1 = nn.ConvTranspose2d(f*2, f, 2, stride=2)
        self.dec1 = DoubleConv(f*2, f)
        self.out_conv = nn.Conv2d(f, out_ch, 1)
    
    def forward(self, x):
        e1 = self.enc1(x)
        e2 = self.enc2(self.pool(e1))
        e3 = self.enc3(self.pool(e2))
        e4 = self.enc4(self.pool(e3))
        b = self.bottleneck(self.pool(e4))
        d4 = self.dec4(torch.cat([self.upconv4(b), e4], dim=1))
        d3 = self.dec3(torch.cat([self.upconv3(d4), e3], dim=1))
        d2 = self.dec2(torch.cat([self.upconv2(d3), e2], dim=1))
        d1 = self.dec1(torch.cat([self.upconv1(d2), e1], dim=1))
        return self.out_conv(d1)

# 加载 GOPRO 权重
model = UNet(in_ch=3, out_ch=3, base_filters=32)
state_dict = {}
name_mapping = {
    'enc1.0.weight': 'enc1.conv.0.weight', 'enc1.0.bias': 'enc1.conv.0.bias',
    'enc1.2.weight': 'enc1.conv.2.weight', 'enc1.2.bias': 'enc1.conv.2.bias',
    # ... （完整映射参见代码）
}
for gguf_name, torch_name in name_mapping.items():
    state_dict[torch_name] = torch.from_numpy(gopro_weights[gguf_name])
model.load_state_dict(state_dict)
model.eval()

# 推理
img = Image.open('blurry.jpg').convert('RGB').resize((128, 128))
img_np = np.array(img, dtype=np.float32) / 255.0
input_tensor = torch.from_numpy(img_np.transpose(2, 0, 1)).unsqueeze(0)
with torch.no_grad():
    output = model(input_tensor)
output_img = (output.squeeze().numpy().transpose(1, 2, 0) * 255).astype(np.uint8)
Image.fromarray(output_img).save('deblurred.jpg')
```

### VFI 视频帧插值推理 (PyTorch)

```python
# 使用与上述相同的 UNet 类，但 in_ch=6
vfi_model = UNet(in_ch=6, out_ch=3, base_filters=32)
vfi_model.load_state_dict(vfi_state_dict)
vfi_model.eval()

# 输入：第1帧和第4帧（两边界帧）
frame1 = Image.open('frame1.jpg').convert('RGB').resize((128, 128))
frame4 = Image.open('frame4.jpg').convert('RGB').resize((128, 128))

# 拼接为 6 通道输入
arr1 = np.array(frame1, dtype=np.float32) / 255.0
arr4 = np.array(frame4, dtype=np.float32) / 255.0
combined = np.concatenate([arr1.transpose(2,0,1), arr4.transpose(2,0,1)], axis=0)
input_tensor = torch.from_numpy(combined).unsqueeze(0)

# 预测中间帧
with torch.no_grad():
    middle_frame = vfi_model(input_tensor)
```

### 图像分类推理 (PyTorch)

```python
import torch
import torch.nn as nn

class CNNClassifier(nn.Module):
    def __init__(self, num_classes=13):
        super().__init__()
        self.layers = nn.Sequential(
            # Block 1
            nn.Conv2d(3, 32, 3, padding=1),
            nn.BatchNorm2d(32),
            nn.ReLU(),
            nn.MaxPool2d(2),
            # Block 2
            nn.Conv2d(32, 64, 3, padding=1),
            nn.BatchNorm2d(64),
            nn.ReLU(),
            nn.MaxPool2d(2),
            # Block 3
            nn.Conv2d(64, 128, 3, padding=1),
            nn.BatchNorm2d(128),
            nn.ReLU(),
            nn.MaxPool2d(2),
            # Block 4
            nn.Conv2d(128, 256, 3, padding=1),
            nn.BatchNorm2d(256),
            nn.ReLU(),
            nn.MaxPool2d(2),
            # GAP + Classifier
            nn.AdaptiveAvgPool2d(1),
            nn.Flatten(),
            nn.Linear(256, 256),
            nn.ReLU(),
            nn.Linear(256, num_classes),
        )
    def forward(self, x):
        return self.layers(x)

# VINS 13类分类
vins_model = CNNClassifier(num_classes=13)
vins_model.eval()

# NOOB2EDIT 15类分类
noob2edit_model = CNNClassifier(num_classes=15)
noob2edit_model.eval()
```

---

## 训练框架

### Mocode DeepLearningEngine

本模型使用 **Mocode 深度学习引擎** 训练，这是一个基于 PyTorch 的自定义深度学习框架，集成于 Mocode 脚本语言解释器中。

**核心特性**:
- 支持 MLP / CNN / U-Net / Transformer 等多种网络架构
- 支持分类和回归任务
- 内置学习率调度器 (Cosine / Linear / Exponential)
- 支持早停机制
- 支持 GPU (CUDA) 加速训练
- 直接支持 GGUF 格式模型导出

**Mocode 脚本语法示例**:
```
// 创建 U-Net 网络
network gopro_unet : unet(in_channels=3, out_channels=3, base_filters=32)

// 加载数据集
dataset gopro_data : image_dataset("gopro_data.npz", type="regression")

// 训练
train gopro_unet on gopro_data with {
    epochs: 30,
    batch_size: 8,
    optimizer: "Adam",
    learning_rate: 0.001,
    lr_scheduler: "cosine",
    loss: "MSE"
}

// 导出 GGUF
export_gguf gopro_unet to "gopro_unet.gguf"
```

---

## 模型性能对比

| 子模型 | 任务 | 架构 | 参数量 | 指标 | 最佳值 | 训练时间 |
|--------|------|------|--------|------|--------|----------|
| GOPRO | 图像去模糊 | U-Net | 7.77M | PSNR | 28.46 dB | 3.8 min |
| VINS | 编辑分类(13类) | CNN | 0.46M | Accuracy | 100% | 11.7 s |
| NOOB2EDIT | CG编辑分类(15类) | CNN | 0.46M | Accuracy | 100% | 10.6 s |
| VFI | 视频帧插值 | U-Net | 7.77M | PSNR | 19.42 dB | 3.8 min |

---

## 注意事项

1. **输入预处理**: 所有图像输入需归一化到 [0, 1] 范围，通道顺序为 (C, H, W)
2. **U-Net 输入尺寸**: 128×128（GOPRO 和 VFI），建议使用 2 的幂次尺寸
3. **CNN 输入尺寸**: 64×64（VINS 和 NOOB2EDIT）
4. **VFI 输入**: 需将两帧图像在通道维拼接为 6 通道
5. **分类输出**: 最后一层为 Linear 激活（原始 logits），需手动加 softmax 获取概率
6. **GGUF 张量维度**: GGUF 格式维度为反序（row-major），读取时需注意反转
7. **数据对齐**: 张量数据按 32 字节对齐，读取时需正确计算偏移

---

## 版本历史

| 版本 | 日期 | 说明 |
|------|------|------|
| 1.0.0 | 2026-07-17 | 初始版本，集成 4 个子模型 |

---

## License

Apache License 2.0
