Unlock Image Processing Power with PLKSR Tiled Inference Actions

25 Apr 2025
Unlock Image Processing Power with PLKSR Tiled Inference Actions

In the world of image processing, efficiency and quality are paramount. The ocg2347/plksr-tiled-lowvram spec provides developers with a powerful toolset known as Cognitive Actions, specifically designed to execute tiled inference implementations of PLKSR (Progressive Low-memory Kernel Super Resolution). These pre-built actions allow you to process images of varying dimensions while applying advanced scaling methods, making it easier to integrate high-quality image processing capabilities into your applications.

Prerequisites

Before you start integrating the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which is required for authentication.
  • Basic setup for making HTTP requests, typically by including your API key in the headers.

For authentication, you would generally pass the API key in the request headers as follows:

Authorization: Bearer YOUR_COGNITIVE_ACTIONS_API_KEY

Cognitive Actions Overview

Perform PLKSR Tiled Inference

The Perform PLKSR Tiled Inference action executes a tiled inference implementation of PLKSR, leveraging specific checkpoints tailored for different image types such as general, outdoor, and portrait. This operation optimizes the processing of images with varying dimensions using advanced scaling techniques.

  • Category: image-processing

Input

The input for this action is structured as follows:

  • image (required): The URI of the input image to be processed.
  • batchSize (optional): Specifies the number of images processed in one batch (default is 8, maximum is 64).
  • imageType (optional): Defines the category of the image (default is "general"; options are "general", "portrait", "outdoor").
  • tileWidth (optional): Specifies the width of each tile in pixels (default is 512; options are 128, 256, 512, or 1024).
  • tileHeight (optional): Defines the height of each tile in pixels (default is 512; options are 128, 256, 512, or 1024).
  • scaleFactor (optional): Sets the scale factor for processing (default is 4; range is 1 to 4).
  • tileOverlap (optional): Determines the number of pixels each tile overlaps with adjacent tiles (default is 64; options are 32, 64, or 128).

Example Input:

{
  "image": "https://replicate.delivery/pbxt/MS5ByHEEA9rxVeDv8sPaiPhfsBnyegXry5xl6podPKW26M6Y/lion1.png",
  "batchSize": 24,
  "imageType": "general",
  "tileWidth": 512,
  "tileHeight": 512,
  "scaleFactor": 4,
  "tileOverlap": 64
}

Output

Upon successful execution, the action returns a URI to the processed image.

Example Output:

https://assets.cognitiveactions.com/invocations/28020318-f9d5-490a-a951-75295bab7eff/17980211-70d5-4696-9a06-3cf25e31a296.png

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Perform PLKSR Tiled Inference action:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "1a7adb6d-cf02-41d5-8a42-bb88eab7f0dd" # Action ID for Perform PLKSR Tiled Inference

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/MS5ByHEEA9rxVeDv8sPaiPhfsBnyegXry5xl6podPKW26M6Y/lion1.png",
    "batchSize": 24,
    "imageType": "general",
    "tileWidth": 512,
    "tileHeight": 512,
    "scaleFactor": 4,
    "tileOverlap": 64
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action_id should correspond to the ID of the Perform PLKSR Tiled Inference action.
  • The input payload is structured according to the action's requirements.

Conclusion

The ocg2347/plksr-tiled-lowvram spec provides a robust Cognitive Action that simplifies the process of high-quality image processing. By leveraging the Perform PLKSR Tiled Inference action, developers can efficiently process images tailored to their specific needs. As you explore integrating this action into your applications, consider the various parameters available to optimize your results. Happy coding!