Comments (2)
Thank you @Yuki-11 .
from cssr.
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.
- 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()
-
Load the image(s) to test as np.array.
-
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
- 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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cssr.