---
title: garbage_competition
canonical_url: "https://www.modelscope.cn/datasets/swift/garbage_competition"
md_url: "https://www.modelscope.cn/datasets/swift/garbage_competition.md"
repository: swift/garbage_competition
last_updated: 2025-02-15
license: "Apache License 2.0"
storage_size: "9.1 GB"
downloads: 11197
stars: 2
---

# garbage_competition

> garbage_competition - swift 在 ModelScope 开源的数据集。数据集地址：https://modelscope.cn/datasets/swift/garbagecompetition 数据集下载：

swift/garbage_competition 是 ModelScope 魔搭社区上的数据集，存储大小 9.1 GB，采用 Apache License 2.0 许可。

- **Repository**: swift/garbage_competition
- **License**: Apache License 2.0
- **Storage size**: 9.1 GB
- **Downloads**: 11197
- **Stars**: 2
- **Last updated**: 2025-02-15

Source: https://www.modelscope.cn/datasets/swift/garbage_competition

---

## 数据集

数据集地址：https://modelscope.cn/datasets/swift/garbage_competition
数据集下载：
```python
from modelscope import MsDataset
dataset = MsDataset.load('swift/garbage_competition', split='train')
test_dataset = MsDataset.load('swift/garbage_competition', split='test')
print(dataset)
print(test_dataset)
"""
Dataset({
    features: ['images', 'label', 'label_name'],
    num_rows: 100000
})
Dataset({
    features: ['images', 'label', 'label_name'],
    num_rows: 2650
})
"""
print(dataset[0])
print(test_dataset[0])
"""
{'images': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=750x643 at 0x7F03D82937C0>, 'label': 169, 'label_name': '可回收物-电话'}
{'images': <PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=720x540 at 0x7F03D81FCD00>, 'label': None, 'label_name': None}
"""
```


## Baseline

以下介绍使用ms-swift大模型训练框架，对Qwen2.5-VL-3B-Instruct使用该数据集进行LoRA微调的baseline
- ms-swift github：https://github.com/modelscope/ms-swift
- 以下提供的baseline所需显存资源14GB，可在魔搭免费算力A10上运行
- 该baseline的准确率为: 0.8528301886792453

环境准备：
```shell
pip install ms-swift -U
```

单卡训练：
```python
# GPU Memory: 14GB
import os
from typing import Dict, Any
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ['MAX_PIXELS'] = str(1280 * 28 * 28)

from swift.llm import (
    TrainArguments, sft_main, register_dataset, DatasetMeta, ResponsePreprocessor, SubsetDataset
)

class CustomPreprocessor(ResponsePreprocessor):

    def preprocess(self, row: Dict[str, Any]) -> Dict[str, Any]:
        row['query'] = 'Task: Sorting Waste.'
        return super().preprocess(row)

register_dataset(
    DatasetMeta(
        ms_dataset_id='swift/garbage_competition',
        preprocess_func=CustomPreprocessor(),
        subsets=[SubsetDataset('train', split=['train']), SubsetDataset('test', split=['test'])]
    ))

if __name__ == '__main__':
    sft_main(TrainArguments(
        model='Qwen/Qwen2.5-VL-3B-Instruct',
        dataset=['swift/garbage_competition:train#20000'],  # 节约时间，只选择20000条数据集
        train_type='lora',
        torch_dtype='bfloat16',
        num_train_epochs=1,
        per_device_train_batch_size=1,
        per_device_eval_batch_size=1,
        learning_rate=1e-4,
        lora_rank=8,
        lora_alpha=32,
        target_modules=['all-linear'],
        freeze_vit=True,
        gradient_accumulation_steps=16,
        eval_steps=50,
        save_steps=50,
        save_total_limit=2,
        logging_steps=5,
        max_length=2048,
        output_dir='output',
        warmup_ratio=0.05,
        dataset_num_proc=4,
        dataloader_num_workers=4,
        num_labels=265,
        task_type='seq_cls',
        use_chat_template=False
    ))
```

## 提交结果

我们提供了推理脚本, 最终需要将以下推理脚本产生的`infer_result`目录中的jsonl文件进行提交 (由于比赛界面只允许传递json后缀的文件, 请重命名为`result.json`, 不需要改内容).

```python
# GPU Memory: 14GB
import os
from typing import Dict, Any
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
os.environ['MAX_PIXELS'] = str(1280 * 28 * 28)

from swift.llm import (
    InferArguments, infer_main, register_dataset, DatasetMeta, ResponsePreprocessor, SubsetDataset
)

class CustomPreprocessor(ResponsePreprocessor):

    def preprocess(self, row: Dict[str, Any]) -> Dict[str, Any]:
        row['query'] = 'Task: Sorting Waste.'
        return super().preprocess(row)

register_dataset(
    DatasetMeta(
        ms_dataset_id='swift/garbage_competition',
        preprocess_func=CustomPreprocessor(),
        subsets=[SubsetDataset('train', split=['train']), SubsetDataset('test', split=['test'])]
    ))


ckpt_dir = 'output/vx-xxx/checkpoint-xxx'  # last_checkpoint
result = infer_main(InferArguments(
    adapters=[ckpt_dir],
    temperature=0, 
    val_dataset="swift/garbage_competition:test",
    infer_backend='pt'))
# 结果会保存在`{ckpt_dir}/infer_result/xxx-xxx.jsonl`中, 提交该文件即可.
# (由于比赛界面只能传递json后缀的文件, 请重命名为`result.json`, 不需要改内容).
```

提交的jsonl文件格式如下，顺序与`test_dataset`顺序一致，共2650条，
```
{"response": "25"}
{"response": "xxx"}
{"response": "xxx"}
```

打分脚本：

```python
from swift.utils import read_from_jsonl
from datasets import load_dataset
labels = load_dataset('parquet', data_files='test_with_labels.parquet', split='train')['label']

results = read_from_jsonl('result.jsonl')
count = 0
for i, (res, label) in enumerate(zip(results, labels)):
    if int(res['response']) == label:
        count += 1
print(f'acc: {count / len(results)}')  
```
