zip大文件在linux下解压数据受损的补救方案——以SPAQ数据集为例

背景

由于SPAQ.zip是大文件,在linux中无法直接unzip解压,所以作者将SPAQ分卷压缩。但即使这样,仍然可能出现数据受损的情况。我记录了大文件解压后遇到的问题和解决办法,希望能帮助到你。

github地址:Giselle0707/SPAQ: CVPR2020 Official SPAQ & Implementation. Addition: dataset unzip problem and solution. (github.com)

如何在linux中解压分卷呢?

  1. 前提

    所有*.z*文件(包括.zip)都已经被放在linux文件夹下。

  2. 解压指令

shell 复制代码
    zip -FF SPAQ.zip --out SPAQ_fixed.zip
    unzip SPAQ_fixed.zip

可能遇到的问题和解决办法

  1. python程序在图像处理过程中报错:"OSErr"

    经过排查,我发现部分图像出现了图像数据部分丢失的情况,这部分图像在被 convert 成 RGB 图像时会丢出 OSErr。人工检查数据集中哪些图像有误是不实际的,所以我写了两段 python 代码分别用于检查损坏的图像和另存一份需要重新上传的未损坏的图像。你需要在linux设备上运行 OutputErrorImages.py,并把它的输出复制后保存到你本地设备的 demagedImgs.txt 文件中。接着,在你的本地设备运行 pickImage.py,以将未损坏的图像保存到 updated 文件夹中,以便于你进一步将这些图像重新上传到 linux 终端。

Codes

For directly apply my codes, your dir tree should be like this:

python 复制代码
### OutputErrorImages.py
### This file is to Test which image is be demaged, and print their name in console. You should copy the output and paste them at your local device as "demagedImgs.txt" and run 'python pickImage.py'.

import os
import os.path
from openpyxl import load_workbook
import torchvision
from torchvision.transforms import transforms
from PIL import Image
import scipy.io
import xlrd
from tqdm import tqdm

## DEFINE Args
root = "" # your SPAQ dataset location
index = list(range(0, 11125))
transform = transforms = torchvision.transforms.Compose([
     torchvision.transforms.ToTensor()])

## START loading SPAQ dataset
data = xlrd.open_workbook(os.path.join(root, 'Annotations/MOS and Image attribute scores.xlsx'))
table = data.sheet_by_index(0)

for rowNum in tqdm(range(table.nrows)):
    if rowNum > 0:
        rowValue = table.row_values(rowNum)
        # acquire imgnames, convert them into RGB. If OSErr was throw, then print their name for record.
        try:
            sample = pil_loader(os.path.join(root, 'TestImage', rowValue[0]))
        except OSError as e:
            print(os.path.join(root, 'TestImage', rowValue[0]))
print("Success")
python 复制代码
### pickImage.py 
# This file is to copy the undemaged images into dst dir, for use to re-upload these images.

import os
from PIL import Image
import os.path
import shutil

dst = "./updated/" # image folder which should contains the indamaged images correspponding to the demaged images.
file_name = "demagedImgs.txt"

def openreadtxt(file_name):
    file = open(file_name,'r')  
    file_data = file.readlines() 
    for row in file_data:
        row = row.strip('\n')
        shutil.copy(f"TestImage/{row}", dst)

openreadtxt(file_name)
print("Success")
shell 复制代码
### data transfer tool
### This command is for those whose devide could run linux command. I prefer to transfer data through scp command than using APP SFTP. Window user could run this file in "git bash"!
scp -r -P 22 ./updated.zip user@xx.xx.xx.xx:/dst_location
相关推荐
正在走向自律10 小时前
时序大模型 TimechoAI 实战指南,让时序数据分析从“手工建模“走向“智能预测“
数据挖掘·数据分析·timechodb·时序数据·时序大模型·timechoai
苏灿烤鱼10 小时前
一套进程代替八件套,桌面更稳还是单点更大
linux·github·shell
刘梦薇10 小时前
SSH连接失败connection reset解决办法
linux·运维·ubuntu·ssh·腾讯云
Rsingstarzengjx10 小时前
stm32m157 U-boot 测试
linux·运维·服务器
躺柒10 小时前
读数据可视化05视觉感知
信息可视化·数据挖掘·数据分析·视觉·视觉感知
月落汀兰11 小时前
Linux Nginx全套实战通关|静态站点/虚拟主机/HTTPS/PHP/反向代理/七层负载均衡,每行命令逐参数拆解
linux·nginx·https
ShineWinsu11 小时前
对于C++:缓冲区管理的详细解析
linux·c++·面试·编程·笔试·io·缓冲区
张小姐的猫12 小时前
【Linux】网络编程 —— 传输层协议 TCP(下)
linux·运维·服务器·网络·tcp/ip·http·php
程序员AlbertTu12 小时前
第2章 上手 Linux:环境与文件操作
linux·运维·服务器
☆凡尘清心☆13 小时前
CentOS Stream 9 源码编译搭建 Zabbix7.0.29 完整部署方案(部署成功)
linux·运维·centos