### Example Usage of Model Recommendation Source: https://context7.com/phhofm/models/llms.txt This code snippet demonstrates how to use the `recommend_model` function to get a model recommendation for 'anime_video' with a speed priority and prints the result. ```python # Usage model = recommend_model("anime_video", speed_priority=True) print(f"Recommended: {model}") # Output: 2xHFA2kCompact ``` -------------------------------- ### 2xNomosUni_compact_otf_medium Degradation Settings Source: https://github.com/phhofm/models/blob/main/README.md Configuration for the 'medium' degradation pipeline, which reduces the intensity of noise and JPEG compression compared to the 'strong' settings. This aims for a balanced degradation strength. ```yaml # the first degradation process resize_prob: [0.3, 0.4, 0.3] # up, down, keep resize_range: [0.5, 1.5] gaussian_noise_prob: 0.2 noise_range: [0, 2] poisson_scale_range: [0.05, 0.25] gray_noise_prob: 0.1 jpeg_range: [40, 95] #lets crack down on jpg compression, after 148k iter, from 75,95 to 40,95 # the second degradation process second_blur_prob: 0.4 resize_prob2: [0.3, 0.4, 0.3] # up, down, keep resize_range2: [0.5, 1.5] gaussian_noise_prob2: 0.2 noise_range2: [0, 2] poisson_scale_range2: [0.05, 0.1] gray_noise_prob2: 0.1 jpeg_range2: [40, 95] #jpg compression crackdown, after 148k iter, from 75,95 to 40,95 blur_kernel_size: 7 kernel_list: ["iso", "aniso", "generalized_iso", "generalized_aniso", "plateau_iso", "plateau_aniso"] kernel_prob: [0.45, 0.25, 0.12, 0.03, 0.12, 0.03] sinc_prob: 0.1 blur_sigma: [0.2, 3] betag_range: [0.5, 4] betap_range: [1, 2] blur_kernel_size2: 9 kernel_list2: ["iso", "aniso", "generalized_iso", "generalized_aniso", "plateau_iso", "plateau_aniso"] kernel_prob2: [0.45, 0.25, 0.12, 0.03, 0.12, 0.03] sinc_prob2: 0.1 blur_sigma2: [0.2, 1.5] betag_range2: [0.5, 4] betap_range2: [1, 2] ``` -------------------------------- ### 2xNomosUni_compact_otf_weak Degradation Settings Source: https://github.com/phhofm/models/blob/main/README.md Configuration for the 'weak' degradation pipeline, characterized by significantly reduced noise levels and a narrower range for resizing and JPEG compression. This setting is for minimal degradation. ```yaml # the first degradation process resize_prob: [0.3, 0.4, 0.3] # up, down, keep resize_range: [0.85, 1.25] gaussian_noise_prob: 0.2 noise_range: [0, 1] poisson_scale_range: [0.05, 0.1] gray_noise_prob: 0.1 jpeg_range: [85, 100] ``` -------------------------------- ### 2xNomosUni_compact_otf_strong Degradation Settings Source: https://github.com/phhofm/models/blob/main/README.md Configuration for the 'strong' degradation pipeline, featuring higher probabilities and ranges for noise and blur, along with specific JPEG compression settings. This is intended for training robust models. ```yaml # the first degradation process resize_prob: [0.3, 0.4, 0.3] # up, down, keep resize_range: [0.5, 1.5] gaussian_noise_prob: 0.2 noise_range: [0, 4] poisson_scale_range: [0.05, 0.5] gray_noise_prob: 0.1 jpeg_range: [70, 95] # the second degradation process second_blur_prob: 0.8 resize_prob2: [0.3, 0.4, 0.3] # up, down, keep resize_range2: [0.3, 1.5] gaussian_noise_prob2: 0.2 noise_range2: [0, 4] poisson_scale_range2: [0.05, 0.25] gray_noise_prob2: 0.1 jpeg_range2: [60, 95] blur_kernel_size: 7 kernel_list: ["iso", "aniso", "generalized_iso", "generalized_aniso", "plateau_iso", "plateau_aniso"] kernel_prob: [0.45, 0.25, 0.12, 0.03, 0.12, 0.03] sinc_prob: 0.1 blur_sigma: [0.2, 3] betag_range: [0.5, 4] betap_range: [1, 2] blur_kernel_size2: 9 kernel_list2: ["iso", "aniso", "generalized_iso", "generalized_aniso", "plateau_iso", "plateau_aniso"] kernel_prob2: [0.45, 0.25, 0.12, 0.03, 0.12, 0.03] sinc_prob2: 0.1 blur_sigma2: [0.2, 1.5] betag_range2: [0.5, 4] betap_range2: [1, 2] ``` -------------------------------- ### Default Degradation Settings (Second Process) Source: https://github.com/phhofm/models/blob/main/README.md Configuration for the second degradation process, including blur, noise, and resizing probabilities and ranges. These settings are part of a baseline or default configuration. ```yaml # the second degradation process second_blur_prob: 0.8 resize_prob2: [0.3, 0.4, 0.3] # up, down, keep resize_range2: [0.3, 1.2] gaussian_noise_prob2: 0.5 noise_range2: [1, 25] poisson_scale_range2: [0.05, 2.5] gray_noise_prob2: 0.4 jpeg_range2: [30, 95] blur_kernel_size: 21 kernel_list: ['iso', 'aniso', 'generalized_iso', 'generalized_aniso', 'plateau_iso', 'plateau_aniso'] kernel_prob: [0.45, 0.25, 0.12, 0.03, 0.12, 0.03] sinc_prob: 0.1 blur_sigma: [0.2, 3] betag_range: [0.5, 4] betap_range: [1, 2] blur_kernel_size2: 21 kernel_list2: ['iso', 'aniso', 'generalized_iso', 'generalized_aniso', 'plateau_iso', 'plateau_aniso'] kernel_prob2: [0.45, 0.25, 0.12, 0.03, 0.12, 0.03] sinc_prob2: 0.1 blur_sigma2: [0.2, 1.5] betag_range2: [0.5, 4] betap_range2: [1, 2] ``` -------------------------------- ### Prepare SISR Dataset Workflow (Python) Source: https://context7.com/phhofm/models/llms.txt Prepares a Super-Resolution (SISR) training dataset by scoring images with HyperIQA, selecting top-quality images, generating multiscales, cropping to tiles, and performing final quality filtering. It takes input and output directories, target image count, and tile size as parameters. ```python import os from pathlib import Path def prepare_sisr_dataset(input_dir: str, output_dir: str, target_count: int = 10000, tile_size: int = 512): """ Prepare a SISR training dataset. Steps: 1. Score images with HyperIQA 2. Keep top N images by quality score 3. Generate multiscales 4. Crop to sub-images 5. Final quality filtering """ # Step 1: Run HyperIQA scoring # hyperiqa scores images 0.0-1.0, higher = better quality scores = run_hyperiqa(input_dir) # Returns dict {filename: score} # Step 2: Sort and keep top images sorted_images = sorted(scores.items(), key=lambda x: x[1], reverse=True) top_images = sorted_images[:target_count] avg_score = sum(s for _, s in top_images) / len(top_images) print(f"Average HyperIQA score of top {target_count}: {avg_score:.4f}") # Step 3: Generate multiscales (1x, 0.75x, 0.5x) scale_list = [1, 0.75, 0.5] for img_name, score in top_images: img_path = os.path.join(input_dir, img_name) generate_multiscales(img_path, output_dir, scale_list) # Step 4: Crop to 512x512 tiles crop_to_subimages(output_dir, tile_size=tile_size) # Step 5: Generate meta_info.txt generate_meta_info(output_dir) return output_dir # Example: Prepare FaceUp dataset from FFHQ prepare_sisr_dataset( input_dir="/path/to/ffhq/images1024x1024", output_dir="/path/to/FaceUp", target_count=2000, tile_size=512 ) ``` -------------------------------- ### Configure Video Compression Degradation (Python) Source: https://github.com/phhofm/models/blob/main/README.md This snippet configures degradation settings for video compression within an options dictionary. It includes parameters for JPEG quality, video codecs and their probabilities, Constant Rate Factor (CRF) ranges and offsets, encoding presets, and auxiliary settings for ratio scaling and FPS. ```python if opt['degradation_mode'] == "V2": # Setting for Degradation with Video Compression (V2) # V1 Skip setting opt['v1_proportion'] = 0.05 # [~0.05] opt['jpeg_range2'] = [30, 95] # V1 JPEG proportion # Codec opt['video_codec'] = ["mpeg2video", "libxvid", "libx264", "libx265"] # codec opt['video_codec_prob'] = [0.2, 0.2, 0.4, 0.2] # CRF opt['crf_range'] = [20, 32] opt['crf_offset'] = [0, 0, 0, 5] # CRF=23: AVC's default value; CRF=8: HEVC's default value opt['mpeg2_4_bitrate_range'] = [3800, 5800] # Preset opt['encode_preset'] = ["slow", "medium", "fast", "faster", "superfast"] opt['encode_preset_prob'] = [0.1, 0.5, 0.25, 0.12, 0.03] # Auxiliary (Ratio Scaling + FPS) opt['ratio_prob'] = [0.2, 0.4, 0.4] # shrink, expand, keep: just width adjust prob opt['ratio_range'] = [0.8, 1.35] # bottom, ceil opt['fps_range'] = [16, 30] ``` -------------------------------- ### Real-ESRGAN OTF Degradation Settings Source: https://github.com/phhofm/models/blob/main/README.md Standard configuration values for the on-the-fly degradation processes in the Real-ESRGAN pipeline. These settings control various degradation types like resizing, noise, and JPEG compression applied during training. ```yaml # the first degradation process resize_prob: [0.2, 0.7, 0.1] # up, down, keep resize_range: [0.15, 1.5] gaussian_noise_prob: 0.5 noise_range: [1, 30] poisson_scale_range: [0.05, 3] gray_noise_prob: 0.4 jpeg_range: [30, 95] ``` -------------------------------- ### Define Image Scaling Parameters Source: https://github.com/phhofm/models/blob/main/Guides/DatasetPreparation.md This code snippet defines the scaling factors and the shortest edge dimension for generating multiscale images. It specifies the list of scales to apply and the base resolution for the smallest image, which helps in creating a diverse dataset for model training. ```python scale_list = [1, 0.75] shortest_edge = 512 ``` -------------------------------- ### Configure RealESRGAN for Photo Upscaling (YAML) Source: https://context7.com/phhofm/models/llms.txt This configuration defines the parameters for the 4xNomos8kSC model, designed for realistic photo super-resolution. It utilizes the RRDBNet architecture and specifies on-the-fly degradation settings for JPEG compression and blur. ```yaml # 4xNomos8kSC Training Configuration name: 4xNomos8kSC model_type: RealESRGANModel scale: 4 num_gpu: auto manual_seed: 0 # Disable USM sharpening l1_gt_usm: False percep_gt_usm: False gan_gt_usm: False # OTF degradation settings (compression + blur, no noise) resize_prob: [0.2, 0.7, 0.1] resize_range: [0.15, 1.5] gaussian_noise_prob: 0 noise_range: [0, 0] jpeg_range: [75, 95] second_blur_prob: 0.8 resize_prob2: [0.3, 0.4, 0.3] resize_range2: [0.3, 1.2] jpeg_range2: [75, 95] gt_size: 256 queue_size: 180 datasets: train: name: Nomos8k_sfw type: RealESRGANDataset dataroot_gt: /path/to/nomos8k_sfw meta_info: /path/to/nomos8k_sfw_meta_info.txt blur_kernel_size: 12 kernel_list: ['iso', 'aniso', 'generalized_iso', 'generalized_aniso', 'plateau_iso', 'plateau_aniso'] kernel_prob: [0.65, 0.25, 0.12, 0.03, 0.12, 0.03] blur_sigma: [0.2, 3] gt_size: 256 use_hflip: True use_rot: True batch_size_per_gpu: 10 network_g: type: RRDBNet num_in_ch: 3 num_out_ch: 3 num_feat: 64 num_block: 23 num_grow_ch: 32 path: pretrain_network_g: experiments/pretrained_models/RealESRGAN_x4plus.pth param_key_g: params_ema train: ema_decay: 0.999 optim_g: type: Adam lr: !!float 1e-4 betas: [0.9, 0.99] total_iter: 400000 pixel_opt: type: L1Loss loss_weight: 1.0 perceptual_opt: type: PerceptualLoss vgg_type: vgg19 perceptual_weight: !!float 1e-1 gan_opt: type: GANLoss loss_weight: !!float 1e-1 ``` -------------------------------- ### Configure SRVGGNet for Anime Upscaling with AVC (YAML) Source: https://context7.com/phhofm/models/llms.txt This configuration details the 2xHFA2kAVCCompact model, utilizing the SRVGGNetCompact architecture for upscaling anime frames with AVC (H.264) compression artifacts. It employs paired training on the HFA2k dataset. ```yaml # 2xHFA2kAVCCompact Training Configuration name: 2xHFA2kAVCCompact model_type: RealESRGANModel scale: 2 num_gpu: 1 # Disable USM and high-order degradation (using paired dataset) l1_gt_usm: False percep_gt_usm: False gan_gt_usm: False high_order_degradation: False datasets: train: name: HFA2k_LUDVAE type: PairedImageDataset dataroot_gt: /path/to/HFA2k # High-quality ground truth dataroot_lq: /path/to/HFA2k_h264 # H.264 compressed low-quality inputs gt_size: 256 use_hflip: true use_rot: true batch_size_per_gpu: 4 val: name: validation type: PairedImageDataset dataroot_gt: /path/to/HFA2kvalHR dataroot_lq: /path/to/HFA2kvalLRh264 network_g: type: SRVGGNetCompact num_in_ch: 3 num_out_ch: 3 num_feat: 64 num_conv: 16 upscale: 2 act_type: prelu train: ema_decay: 0.999 optim_g: type: AdamW lr: !!float 1.5e-4 betas: [0.9, 0.99] total_iter: 500000 pixel_opt: type: L1Loss loss_weight: 1.0 perceptual_opt: type: PerceptualLoss perceptual_weight: !!float 1.0 contextual_opt: type: ContextualLoss loss_weight: 0.5 color_opt: type: ColorLoss loss_weight: 1.0 avg_opt: type: AverageLoss loss_weight: 1.0 scale: 2 gan_opt: type: GANLoss loss_weight: !!float 1e-1 val: val_freq: 1000 save_img: true metrics: psnr: type: calculate_psnr crop_border: 4 ssim: type: calculate_ssim crop_border: 4 ``` -------------------------------- ### Benchmark Results for Image Super Resolution Models Source: https://context7.com/phhofm/models/llms.txt This dictionary contains benchmark results for various super resolution models, including their inference time and frames per second (FPS). It is used to evaluate and compare model performance. ```python BENCHMARK_RESULTS = { # Fast lightweight models "Compact (SRVGGNet)": {"time": 1.90, "fps": 26.35}, "SPAN": {"time": 2.33, "fps": 21.44}, "SAFMN": {"time": 2.92, "fps": 17.11}, # Medium models "SeemoRe_t": {"time": 4.07, "fps": 12.29}, "DITN": {"time": 4.26, "fps": 11.72}, "CUGAN": {"time": 4.45, "fps": 11.22}, "PLKSR_tiny": {"time": 4.42, "fps": 11.31}, "RealPLKSR": {"time": 9.90, "fps": 5.05}, "OmniSR": {"time": 8.90, "fps": 5.62}, # Large models (slower but higher quality) "ESRGAN (RRDBNet)": {"time": 22.51, "fps": 2.22}, "SwinIR-M": {"time": 46.46, "fps": 1.08}, "DAT2": {"time": 81.90, "fps": 0.61}, "HAT-S": {"time": 71.37, "fps": 0.70}, "HAT-L": {"time": 177.75, "fps": 0.28}, "ATD": {"time": 152.13, "fps": 0.33}, } ``` -------------------------------- ### Model Recommendation Function Source: https://context7.com/phhofm/models/llms.txt This Python function recommends a super resolution model based on the specified use case and whether speed is a priority. It returns a model name or None if the use case or priority is not recognized. ```python def recommend_model(use_case: str, speed_priority: bool = False): """Recommend model based on use case and speed requirements.""" recommendations = { "anime_video": { "fast": "2xHFA2kCompact", "balanced": "2xHFA2kAVCOmniSR", "quality": "2xHFA2kAVCSRFormer_light" }, "photo_web": { "fast": "4xLSDIRCompactC3", "balanced": "4xNomos8kSC", "quality": "4xNomos8kSCHAT-L" }, "ai_generated": { "fast": "2xLexicaRRDBNet", "balanced": "2xLexicaSwinIR", "quality": "4xLexicaHAT" } } priority = "fast" if speed_priority else "balanced" return recommendations.get(use_case, {}).get(priority) ```