Code Monkey home page Code Monkey logo

Comments (2)

ashutoshbk avatar ashutoshbk commented on June 16, 2024 1

Thank you @Yuki-11 .

from cssr.

Yuki-11 avatar Yuki-11 commented on June 16, 2024

Apologies for the delayed response. Below, I've outlined some implementation guidelines. Please note that these are just guidelines, so you'll need to implement the details yourself.

  1. Create an instance of the model, similar to part of the implementation in test.py:
def test(args, cfg):
    device = torch.device(cfg.DEVICE)
    if cfg.MODEL.SR_SEG_INV:
        model = InvModel(cfg).to(device)
        print(f'------------Model Architecture-------------\n\n<Network SS>\n{model.segmentation_model}\n\n<Network SR>\n{model.sr_model}')
    else:
        model = Model(cfg).to(device)
        print(f'------------Model Architecture-------------\n\n<Network SR>\n{model.sr_model}\n\n<Network SS>\n{model.segmentation_model}')

    model.load_state_dict(fix_model_state_dict(torch.load(args.trained_model, map_location=lambda storage, loc:storage)))
    model.eval()
  1. Load the image(s) to test as np.array.

  2. Convert the loaded image(s) into a format that can be inputted into the model, referring to the TestTransform in data_preprocess.py.

class TestTransforms:
    def __init__(self, cfg):
        self.augment = Compose([
            ConvertFromInts(),
            ToTensor(),
        ])

    def __call__(self, image, mask):
        image, mask = self.augment(image, mask)
        if mask is not None:
            return image/255, mask/255
        
        return image/255, None
  1. For inference on a single image, reshape it into the shape (1, 3, H, W), perform inference with the model, and save the output. You can refer to inference.py for this.
sr_preds, segment_preds = model(imgs)

# SR evaluation
if not cfg.MODEL.SR_SEG_INV and cfg.MODEL.SCALE_FACTOR != 1:
    sr_preds[sr_preds>1] = 1 # clipping
    sr_preds[sr_preds<0] = 0 # clipping        
    psnr_scores = np.append(psnr_scores, psnr(sr_preds, sr_targets.to("cuda"))) 
    ssim_scores = np.append(ssim_scores, ssim(sr_preds, sr_targets.to("cuda"))) 
    save_img(args.output_dirname, sr_preds, fname)

These steps should guide you in performing inference on new images using your model.

We plan to add a demo script to CSBSR, an advanced version of CSSR, that allows inference from a single image at a later date. Please look forward to this as well! 

from cssr.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.