|
|
import os |
|
|
from PIL import Image |
|
|
from pathlib import Path |
|
|
import numpy as np |
|
|
import random |
|
|
|
|
|
|
|
|
|
|
|
import re |
|
|
import json |
|
|
|
|
|
|
|
|
base_rt = f'/home/work/shared-fi-datasets-01/users/hsiang.chen/Project/Datasets/IR' |
|
|
dataset_dict = { |
|
|
|
|
|
|
|
|
"HR": { |
|
|
"DIV2K": {'train': 'SuperResolution/DIV2K/metas/DIV2K_train_HR.list', |
|
|
'val': 'SuperResolution/DIV2K/metas/DIV2K_valid_HR.list'}, |
|
|
"Flickr2K": {'train': 'SuperResolution/Flickr2K/metas/Flickr2K_HR.list'}, |
|
|
"OST": {'train': 'SuperResolution/OST/metas/OST_HR.list'}, |
|
|
}, |
|
|
|
|
|
"Low Resolution": { |
|
|
"DIV2K": {'train1': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_SR1.list', |
|
|
'train2': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_SR2.list', |
|
|
'train3': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_SR3.list', |
|
|
'val': 'SuperResolution/DIV2K/metas/DIV2K_valid_pair_SR.list'}, |
|
|
"Flickr2K": {'train1': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_SR1.list', |
|
|
'train2': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_SR2.list', |
|
|
'train3': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_SR3.list'}, |
|
|
"OST": {'train1': 'SuperResolution/OST/metas/OST_train_pair_SR1.list', |
|
|
'train2': 'SuperResolution/OST/metas/OST_train_pair_SR2.list', |
|
|
'train3': 'SuperResolution/OST/metas/OST_train_pair_SR3.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"Rain": { |
|
|
"RainTrainL": {'train': 'Derain/RainTrainL/metas/train.list'}, |
|
|
"Rain100L": {'test': 'Derain/Rain100L/metas/test.list'}, |
|
|
"LHPRain": {'train': 'Derain/LHPRain/metas/train.list', |
|
|
'val': 'Derain/LHPRain/metas/val.list', |
|
|
'test': 'Derain/LHPRain/metas/test.list'}, |
|
|
"UHDRain": {'train': 'Derain/UHD-Rain/metas/train.list', |
|
|
'test': 'Derain/UHD-Rain/metas/test.list'}, |
|
|
"Practical": {'test': 'Derain/Practical/metas/test.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"RainDrop": { |
|
|
"RainDrop": {'train': 'Derain/RainDrop/metas/Raindrop_train.list', |
|
|
'test_a': 'Derain/RainDrop/metas/Raindrop_test_a.list', |
|
|
'test_b': 'Derain/RainDrop/metas/Raindrop_test_b.list'}, |
|
|
"RainDS_syn_rainstreak": {'train': 'Derain/RainDS/metas/RainDS_syn_train_rainstreak.list', |
|
|
'test': 'Derain/RainDS/metas/RainDS_syn_test_rainstreak.list'}, |
|
|
"RainDS_syn_raindrop": {'train': 'Derain/RainDS/metas/RainDS_syn_train_raindrop.list', |
|
|
'test': 'Derain/RainDS/metas/RainDS_syn_test_raindrop.list'}, |
|
|
"RainDS_syn_rainstreak_raindrop": {'train': 'Derain/RainDS/metas/RainDS_syn_train_rainstreak_raindrop.list', |
|
|
'test': 'Derain/RainDS/metas/RainDS_syn_test_rainstreak_raindrop.list'}, |
|
|
"RainDS_real_rainstreak": {'train': 'Derain/RainDS/metas/RainDS_real_train_set_rainstreak.list', |
|
|
'test': 'Derain/RainDS/metas/RainDS_real_test_set_rainstreak.list'}, |
|
|
"RainDS_real_raindrop": {'train': 'Derain/RainDS/metas/RainDS_real_train_set_raindrop.list', |
|
|
'test': 'Derain/RainDS/metas/RainDS_real_test_set_raindrop.list'}, |
|
|
"RainDS_real_rainstreak_raindrop": {'train': 'Derain/RainDS/metas/RainDS_real_train_set_rainstreak_raindrop.list', |
|
|
'test': 'Derain/RainDS/metas/RainDS_real_test_set_rainstreak.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"Fog":{ |
|
|
"SOTS": {'test': 'Dehaze/SOTS/metas/test.list'}, |
|
|
"OTS": {'train': 'Dehaze/OTS/metas/train.list'}, |
|
|
"4kID": {'train': 'Dehaze/4kID/metas/train.list', |
|
|
'test': 'Dehaze/4kID/metas/test.list'}, |
|
|
"Unann": {'test': 'Dehaze/UnannotatedHazyImages/metas/test.list'}, |
|
|
"NH-Haze": {'test': 'Dehaze/NH-Haze/metas/test.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"Noise": { |
|
|
"BSD400": {'train': 'Denoise/BSD400/metas/BSD400.list', |
|
|
'train1': 'Denoise/BSD400/metas/BSD400_Noise_L1.list', |
|
|
'train2': 'Denoise/BSD400/metas/BSD400_Noise_L3.list', |
|
|
'train3': 'Denoise/BSD400/metas/BSD400_Noise_L5.list',}, |
|
|
"WED": {'train': 'Denoise/WaterlooED/metas/WaterlooED.list', |
|
|
'train1': 'Denoise/WaterlooED/metas/WaterlooED_Noise_L1.list', |
|
|
'train2': 'Denoise/WaterlooED/metas/WaterlooED_Noise_L3.list', |
|
|
'train3': 'Denoise/WaterlooED/metas/WaterlooED_Noise_L5.list',}, |
|
|
"BSD68": {'test': 'Denoise/BSD68/metas/BSD68.list', |
|
|
'test1': 'Denoise/BSD68/metas/BSD68_Noise_L1.list', |
|
|
'test2': 'Denoise/BSD68/metas/BSD68_Noise_L3.list', |
|
|
'test3': 'Denoise/BSD68/metas/BSD68_Noise_L5.list'}, |
|
|
"Urban": {'test': 'Denoise/Urban100/metas/Urban100.list', |
|
|
'test1': 'Denoise/Urban100/metas/Urban100_Noise_L1.list', |
|
|
'test2': 'Denoise/Urban100/metas/Urban100_Noise_L3.list', |
|
|
'test3': 'Denoise/Urban100/metas/Urban100_Noise_L5.list'}, |
|
|
"CBSD68": {'test': 'Denoise/CBSD68/metas/CBSD68.list', |
|
|
'test1': 'Denoise/CBSD68/metas/CBSD68_Noise_L1.list', |
|
|
'test2': 'Denoise/CBSD68/metas/CBSD68_Noise_L3.list', |
|
|
'test3': 'Denoise/CBSD68/metas/CBSD68_Noise_L5.list',}, |
|
|
"Kodak": {'test': 'Denoise/Kodak/metas/Kodak.list', |
|
|
'test1': 'Denoise/Kodak/metas/Kodak_Noise_L1.list', |
|
|
'test2': 'Denoise/Kodak/metas/Kodak_Noise_L3.list', |
|
|
'test3': 'Denoise/Kodak/metas/Kodak_Noise_L5.list'}, |
|
|
"McMaster": {'test': 'Denoise/McMaster/metas/McMaster.list', |
|
|
'test1': 'Denoise/McMaster/metas/McMaster_Noise_L1.list', |
|
|
'test2': 'Denoise/McMaster/metas/McMaster_Noise_L3.list', |
|
|
'test3': 'Denoise/McMaster/metas/McMaster_Noise_L5.list'}, |
|
|
"Set12": {'test': 'Denoise/Set12/metas/Set12.list', |
|
|
'test1': 'Denoise/Set12/metas/Set12_Noise_L1.list', |
|
|
'test2': 'Denoise/Set12/metas/Set12_Noise_L3.list', |
|
|
'test3': 'Denoise/Set12/metas/Set12_Noise_L5.list',}, |
|
|
"SIDD": {'train': 'Denoise/SIDD/metas/train.list', |
|
|
'test': 'Denoise/SIDD/metas/test.list'}, |
|
|
|
|
|
"DIV2K": {'train1': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_Noise_L1.list', |
|
|
'train2': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_Noise_L3.list', |
|
|
'train3': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_Noise_L5.list', |
|
|
'val': 'SuperResolution/DIV2K/metas/DIV2K_valid_pair_Noise.list'}, |
|
|
"Flickr2K": {'train1': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_Noise_L1.list', |
|
|
'train2': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_Noise_L3.list', |
|
|
'train3': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_Noise_L5.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"Snow": { |
|
|
"Snow100k": {'train': 'Desnow/Snow100k/metas/train.list'}, |
|
|
"Snow100k-S": {'test': 'Desnow/Snow100k/metas/test_S.list'}, |
|
|
"Snow100k-M": {'test': 'Desnow/Snow100k/metas/test_M.list'}, |
|
|
"Snow100k-L": {'test': 'Desnow/Snow100k/metas/test_L.list'}, |
|
|
"Snow100k-R": {'test': 'Desnow/Snow100k/metas/test_realistic.list'}, |
|
|
"UHDSnow": {'train': 'Desnow/UHD-Snow/metas/train.list', |
|
|
'test': 'Desnow/UHD-Snow/metas/test.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"Blur": { |
|
|
"GoPro": {'train': 'Deblur/GoPro/metas/train.list', |
|
|
'test': 'Deblur/GoPro/metas/test.list'}, |
|
|
"HIDE": {'train': 'Deblur/HIDE/metas/train.list', |
|
|
'test': 'Deblur/HIDE/metas/test.list'}, |
|
|
"RealBlur-J": {'test': 'Deblur/RealBlur-J_ECC_IMCORR_centroid_itensity_ref/metas/test.list'}, |
|
|
"RealBlur-R": {'test': 'Deblur/RealBlur-R_BM3D_ECC_IMCORR_centroid_itensity_ref/metas/test.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"Low-light": { |
|
|
"LOL": {'train': 'LowLight/LOL/metas/train.list', |
|
|
'test': 'LowLight/LOL/metas/test.list'}, |
|
|
"DICM": {'test': 'LowLight/DICM/metas/test.list'}, |
|
|
"MEF": {'test': 'LowLight/MEF/metas/test.list'}, |
|
|
"NPE": {'test': 'LowLight/NPE/metas/test.list'}, |
|
|
"LIME": {'test': 'LowLight/LIME/metas/test.list'}, |
|
|
"VV": {'test': 'LowLight/VV/metas/test.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"Unknown": { |
|
|
"UDC": {'val': 'Other/UDC/metas/val.list', |
|
|
'test': 'Other/UDC/metas/test.list'}, |
|
|
}, |
|
|
|
|
|
|
|
|
"Composite": { |
|
|
"CDD": { |
|
|
'train': 'Composite/CDD11/metas/train.list', |
|
|
'test_haze': 'Composite/CDD11/metas/test_haze.list', |
|
|
'test_haze_rain': 'Composite/CDD11/metas/test_haze_rain.list', |
|
|
'test_haze_snow': 'Composite/CDD11/metas/test_haze_snow.list', |
|
|
'test_low': 'Composite/CDD11/metas/test_low.list', |
|
|
'test_low_haze': 'Composite/CDD11/metas/test_low_haze.list', |
|
|
'test_low_haze_rain': 'Composite/CDD11/metas/test_low_haze_rain.list', |
|
|
'test_low_haze_snow': 'Composite/CDD11/metas/test_low_haze_snow.list', |
|
|
'test_low_rain': 'Composite/CDD11/metas/test_low_rain.list', |
|
|
'test_low_snow': 'Composite/CDD11/metas/test_low_snow.list', |
|
|
'test_rain': 'Composite/CDD11/metas/test_rain.list', |
|
|
'test_snow': 'Composite/CDD11/metas/test_snow.list', |
|
|
}, |
|
|
}, |
|
|
} |
|
|
|
|
|
def IRImageData(listfile): |
|
|
|
|
|
paths = [] |
|
|
with open(listfile) as fin: |
|
|
for line in fin: |
|
|
line = line.strip().split() |
|
|
if len(line) == 3: |
|
|
paths.append(line) |
|
|
paths = sorted(paths) |
|
|
|
|
|
LQ_list = [] |
|
|
HQ_list = [] |
|
|
labels = [] |
|
|
for data in paths: |
|
|
lq_pth, hq_pth, label = data |
|
|
if os.path.isfile(lq_pth): |
|
|
LQ_list.append(lq_pth) |
|
|
else: |
|
|
LQ_list.append(None) |
|
|
|
|
|
if os.path.isfile(hq_pth): |
|
|
HQ_list.append(hq_pth) |
|
|
else: |
|
|
HQ_list.append(None) |
|
|
|
|
|
|
|
|
return LQ_list, HQ_list |
|
|
|
|
|
|
|
|
question_dict = { |
|
|
"Full-Reference": { |
|
|
"ONE": [ |
|
|
"Compared to the reference, what ONE distortion stands out most in the evaluated image?", |
|
|
"Determine the leading ONE degradation when comparing the evaluated image to the reference.", |
|
|
"Determine the most impactful ONE distortion in the evaluated image compared to the reference.", |
|
|
"Highlight the most significant ONE distortion in the evaluated image in comparison to the reference.", |
|
|
"Identify the chief ONE degradation in the evaluated image when compared to the reference.", |
|
|
"Identify the most notable ONE distortion in the evaluated image's quality when compared to the reference.", |
|
|
"In comparison to the reference, what ONE distortion is most prominent in the evaluated image?", |
|
|
"What ONE distortion is most apparent in the evaluated image relative to the reference?", |
|
|
"What ONE distortion most significantly affects the evaluated image compared to the reference?", |
|
|
"What ONE distortion stands out in the evaluated image against the reference?", |
|
|
"What critical ONE quality degradation is present in the evaluated image versus the reference?", |
|
|
], |
|
|
"TWO": [ |
|
|
"Compared to the reference, what TWO distortions stand out most in the evaluated image?", |
|
|
"Determine the leading TWO degradations when comparing the evaluated image to the reference.", |
|
|
"Determine the most impactful TWO distortions in the evaluated image compared to the reference.", |
|
|
"Highlight the most significant TWO distortions in the evaluated image in comparison to the reference.", |
|
|
"Identify the chief TWO degradations in the evaluated image when compared to the reference.", |
|
|
"Identify the most notable TWO distortions in the evaluated image's quality when compared to the reference.", |
|
|
"In comparison to the reference, what TWO distortions are most prominent in the evaluated image?", |
|
|
"What TWO distortions are most apparent in the evaluated image relative to the reference?", |
|
|
"What TWO distortions most significantly affect the evaluated image compared to the reference?", |
|
|
"What TWO distortions stand out in the evaluated image against the reference?", |
|
|
"What critical TWO quality degradations are present in the evaluated image versus the reference?", |
|
|
], |
|
|
"Common": [ |
|
|
"Compared to the reference, what distortion(s) stand out most in the evaluated image?", |
|
|
"Determine the leading degradation(s) when comparing the evaluated image to the reference.", |
|
|
"Determine the most impactful distortion(s) in the evaluated image compared to the reference.", |
|
|
"Highlight the most significant distortion(s) in the evaluated image in comparison to the reference.", |
|
|
"Identify the chief degradation(s) in the evaluated image when compared to the reference.", |
|
|
"Identify the most notable distortion(s) in the evaluated image's quality when compared to the reference.", |
|
|
"In comparison to the reference, what distortion(s) are most prominent in the evaluated image?", |
|
|
"What critical quality degradation(s) are present in the evaluated image versus the reference?", |
|
|
"What distortion(s) are most apparent in the evaluated image relative to the reference?", |
|
|
"What distortion(s) most significantly affect the evaluated image compared to the reference?", |
|
|
"What distortion(s) stand out in the evaluated image against the reference?" |
|
|
] |
|
|
}, |
|
|
"Non-Reference": { |
|
|
"ONE": [ |
|
|
"Determine the leading ONE degradation in the evaluated image.", |
|
|
"Determine the most impactful ONE distortion in the evaluated image.", |
|
|
"Highlight the most significant ONE distortion in the evaluated image.", |
|
|
"Identify the chief ONE degradation in the evaluated image.", |
|
|
"Identify the most critical ONE distortion in the evaluated image.", |
|
|
"Identify the most notable ONE distortion in the evaluated image's quality.", |
|
|
"In terms of image quality, what is the most glaring ONE issue with the evaluated image?", |
|
|
"In the evaluated image, what ONE distortion is most detrimental to image quality?", |
|
|
"Pinpoint the foremost ONE image quality issue in the evaluated image.", |
|
|
"What ONE distortion is most apparent in the evaluated image?", |
|
|
"What ONE distortion is most evident in the evaluated image?", |
|
|
"What ONE distortion is most prominent in the evaluated image?", |
|
|
"What ONE distortion is most prominent when examining the evaluated image?", |
|
|
"What ONE distortion most detrimentally affects the overall quality of the evaluated image?", |
|
|
"What ONE distortion most notably affects the clarity of the evaluated image?", |
|
|
"What ONE distortion most significantly affects the evaluated image?", |
|
|
"What ONE distortion stands out in the evaluated image?", |
|
|
"What ONE quality degradation is most apparent in the evaluated image?", |
|
|
"What critical ONE quality degradation is present in the evaluated image?", |
|
|
"What is the foremost ONE distortion affecting the evaluated image's quality?", |
|
|
"What is the leading ONE distortion in the evaluated image?", |
|
|
"What is the most critical ONE image quality issue in the evaluated image?", |
|
|
"What is the most severe ONE degradation observed in the evaluated image?", |
|
|
"What is the primary ONE degradation observed in the evaluated image?" |
|
|
], |
|
|
"TWO": [ |
|
|
"Determine the leading TWO degradations in the evaluated image.", |
|
|
"Determine the most impactful TWO distortions in the evaluated image.", |
|
|
"Highlight the most significant TWO distortions in the evaluated image.", |
|
|
"Identify the chief TWO degradations in the evaluated image.", |
|
|
"Identify the most critical TWO distortions in the evaluated image.", |
|
|
"Identify the most notable TWO distortions in the evaluated image's quality.", |
|
|
"In terms of image quality, what are the most glaring TWO issues with the evaluated image?", |
|
|
"In the evaluated image, what TWO distortions are most detrimental to image quality?", |
|
|
"Pinpoint the foremost TWO image quality issues in the evaluated image.", |
|
|
"What TWO distortions are most apparent in the evaluated image?", |
|
|
"What TWO distortions are most evident in the evaluated image?", |
|
|
"What TWO distortions are most prominent in the evaluated image?", |
|
|
"What TWO distortions are most prominent when examining the evaluated image?", |
|
|
"What TWO distortions most detrimentally affect the overall quality of the evaluated image?", |
|
|
"What TWO distortions most notably affect the clarity of the evaluated image?", |
|
|
"What TWO distortions most significantly affect the evaluated image?", |
|
|
"What TWO distortions stand out in the evaluated image?", |
|
|
"What TWO quality degradations are most apparent in the evaluated image?", |
|
|
"What are the foremost TWO distortions affecting the evaluated image's quality?", |
|
|
"What are the leading TWO distortions in the evaluated image?", |
|
|
"What are the most critical TWO image quality issues in the evaluated image?", |
|
|
"What are the most severe TWO degradations observed in the evaluated image?", |
|
|
"What are the primary TWO degradations observed in the evaluated image?", |
|
|
"What critical TWO quality degradations are present in the evaluated image?", |
|
|
], |
|
|
"Common": [ |
|
|
"Determine the leading degradation(s) in the evaluated image.", |
|
|
"Determine the most impactful distortion(s) in the evaluated image.", |
|
|
"Highlight the most significant distortion(s) in the evaluated image.", |
|
|
"Identify the chief degradation(s) in the evaluated image.", |
|
|
"Identify the most critical distortion(s) in the evaluated image.", |
|
|
"Identify the most notable distortion(s) in the evaluated image's quality.", |
|
|
"In terms of image quality, what are the most glaring issue(s) with the evaluated image?", |
|
|
"In the evaluated image, what distortion(s) are most detrimental to image quality?", |
|
|
"Pinpoint the foremost image quality issue(s) in the evaluated image.", |
|
|
"What are the foremost distortion(s) affecting the evaluated image's quality?", |
|
|
"What are the leading distortion(s) in the evaluated image?", |
|
|
"What are the most critical image quality issue(s) in the evaluated image?", |
|
|
"What are the most severe degradation(s) observed in the evaluated image?", |
|
|
"What are the primary degradation(s) observed in the evaluated image?", |
|
|
"What critical quality degradation(s) are present in the evaluated image?", |
|
|
"What distortion(s) are most apparent in the evaluated image?", |
|
|
"What distortion(s) are most evident in the evaluated image?", |
|
|
"What distortion(s) are most prominent in the evaluated image?", |
|
|
"What distortion(s) are most prominent when examining the evaluated image?", |
|
|
"What distortion(s) most detrimentally affect the overall quality of the evaluated image?", |
|
|
"What distortion(s) most notably affect the clarity of the evaluated image?", |
|
|
"What distortion(s) most significantly affect the evaluated image?", |
|
|
"What distortion(s) stand out in the evaluated image?", |
|
|
"What quality degradation(s) are most apparent in the evaluated image?" |
|
|
] |
|
|
} |
|
|
} |
|
|
|
|
|
def question_generate(ref="Full-Reference", degra="Common"): |
|
|
option = f" Answer the question using a single word or phrase." |
|
|
template = random.choice(question_dict[ref]["Common"] + question_dict[ref][degra]) |
|
|
if random.random() >= 0.4: |
|
|
template += option |
|
|
return template |
|
|
|
|
|
if __name__ == "__main__": |
|
|
for degradation, degra_dict in dataset_dict.items(): |
|
|
for dname, ddict in degra_dict.items(): |
|
|
for dset, list_path in ddict.items(): |
|
|
meta_refA = [] |
|
|
meta_A = [] |
|
|
meta_syn = [] |
|
|
|
|
|
|
|
|
paths = [] |
|
|
list_path = os.path.join(base_rt, list_path) |
|
|
with open(list_path) as fin: |
|
|
for line in fin: |
|
|
line = line.strip().split() |
|
|
if len(line) == 3: |
|
|
paths.append(line) |
|
|
paths = sorted(paths) |
|
|
|
|
|
|
|
|
LQ_list = [] |
|
|
HQ_list = [] |
|
|
for data in paths: |
|
|
lq_pth, hq_pth, label = data |
|
|
|
|
|
if os.path.isfile(hq_pth): |
|
|
HQ_list.append(hq_pth) |
|
|
image_ref = os.path.relpath(hq_pth, base_rt).replace("\\", "/") |
|
|
id = os.path.basename(image_ref) |
|
|
else: |
|
|
image_ref = None |
|
|
|
|
|
if os.path.isfile(lq_pth): |
|
|
LQ_list.append(lq_pth) |
|
|
image_A = os.path.relpath(lq_pth, base_rt).replace("\\", "/") |
|
|
id = os.path.basename(image_A) |
|
|
else: |
|
|
image_A = None |
|
|
|
|
|
if degradation == "Composite": |
|
|
key_dict = {"haze": "Fog", |
|
|
"low": "Low-light", |
|
|
"rain": "Rain", |
|
|
"snow": "Snow"} |
|
|
new_label = [] |
|
|
for one_label in label.split("_"): |
|
|
new_label.append(key_dict[one_label]) |
|
|
annotation = ", ".join(new_label) |
|
|
else: |
|
|
annotation = degradation |
|
|
|
|
|
if degradation == "Composite": |
|
|
ref_question = question_generate(ref="Full-Reference", degra="Common") |
|
|
nref_question = question_generate(ref="Non-Reference", degra="Common") |
|
|
else: |
|
|
ref_question = question_generate(ref="Full-Reference", degra="ONE") |
|
|
nref_question = question_generate(ref="Non-Reference", degra="ONE") |
|
|
|
|
|
meta_refA.append({ |
|
|
"distortion_class": degradation, |
|
|
"distortion_name": degradation, |
|
|
"severity": 3, |
|
|
"id": id, |
|
|
"image_ref": image_ref, |
|
|
"image_A": image_A, |
|
|
"image_B": None, |
|
|
"task_type": "quality_single_A", |
|
|
"conversations": [ |
|
|
{ |
|
|
"from": "human", |
|
|
"value": ref_question, |
|
|
}, |
|
|
{ |
|
|
"from": "gpt", |
|
|
"value": annotation |
|
|
} |
|
|
], |
|
|
}) |
|
|
|
|
|
meta_A.append({ |
|
|
"distortion_class": degradation, |
|
|
"distortion_name": degradation, |
|
|
"severity": 3, |
|
|
"id": id, |
|
|
"image_ref": image_ref, |
|
|
"image_A": image_A, |
|
|
"image_B": None, |
|
|
"task_type": "quality_single_A_noref", |
|
|
"conversations": [ |
|
|
{ |
|
|
"from": "human", |
|
|
"value": nref_question, |
|
|
}, |
|
|
{ |
|
|
"from": "gpt", |
|
|
"value": annotation |
|
|
} |
|
|
], |
|
|
}) |
|
|
|
|
|
meta_syn.append({ |
|
|
"distortion_class": degradation, |
|
|
"distortion_name": degradation, |
|
|
"severity": 3, |
|
|
"id": id, |
|
|
"image_ref": image_ref, |
|
|
"image_A": None, |
|
|
"image_B": None, |
|
|
"task_type": "quality_single_A_noref", |
|
|
"conversations": [ |
|
|
{ |
|
|
"from": "human", |
|
|
"value": nref_question, |
|
|
}, |
|
|
{ |
|
|
"from": "gpt", |
|
|
"value": annotation |
|
|
} |
|
|
], |
|
|
}) |
|
|
|
|
|
if len(LQ_list) > 0 and len(HQ_list) > 0 and len(LQ_list) == len(HQ_list): |
|
|
meta_refA_pth = list_path.replace(".list", "_iqa_refA_brief.json") |
|
|
meta_A_pth = list_path.replace(".list", "_iqa_A_brief.json") |
|
|
with open(meta_refA_pth, "w") as f: |
|
|
json.dump(meta_refA, f, indent=4) |
|
|
with open(meta_A_pth, "w") as f: |
|
|
json.dump(meta_A, f, indent=4) |
|
|
|
|
|
print(f"[{os.path.relpath(meta_refA_pth, base_rt)}, ], # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A, {degradation}, {dname}-{dset}") |
|
|
print(f"[{os.path.relpath(meta_A_pth, base_rt)}, ], # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A_noref, {degradation}, {dname}-{dset}") |
|
|
|
|
|
elif len(LQ_list) > 0 and len(HQ_list) == 0: |
|
|
meta_A_pth = list_path.replace(".list", "_iqa_A_brief.json") |
|
|
with open(meta_A_pth, "w") as f: |
|
|
json.dump(meta_A, f, indent=4) |
|
|
print(f"[{os.path.relpath(meta_A_pth, base_rt)}, ], # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A_noref, {degradation}, {dname}-{dset}") |
|
|
|
|
|
elif len(LQ_list) == 0 and len(HQ_list) > 0: |
|
|
meta_refA_pth = list_path.replace(".list", "_iqa_syn_refA_brief.json") |
|
|
meta_syn_pth = list_path.replace(".list", "_iqa_syn_A_brief.json") |
|
|
with open(meta_refA_pth, "w") as f: |
|
|
json.dump(meta_refA, f, indent=4) |
|
|
with open(meta_syn_pth, "w") as f: |
|
|
json.dump(meta_syn, f, indent=4) |
|
|
print(f"[{os.path.relpath(meta_refA_pth, base_rt)}, ], # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A, {degradation}, {dname}-{dset}") |
|
|
print(f"[{os.path.relpath(meta_syn_pth, base_rt)}, ], # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A_noref, {degradation}, {dname}-{dset}") |
|
|
|
|
|
else: |
|
|
raise KeyError(f"the task is not matched, please check the dataset {list_path}") |
|
|
|
|
|
|
|
|
|