由pth转化为pt:
import torch
print(torch.cuda.is_available())
from nets.segformer import SegFormer
ckptfile=“/home/nslidar/Downloads/segformer-pytorch-master/logs/best_epoch_weights.pth”
savedfile=“/home/nslidar/Documents/C++_weight/human_seg.pt111”
net = SegFormer(num_classes=3, phi=“b0”, pretrained=False)
device = torch.device(‘cuda’)
net.load_state_dict(torch.load(ckptfile, map_location=device))
net=net.eval()
x = torch.rand(1,3,512,512)
ts = torch.jit.trace(net, x)
ts.save(savedfile)
C++调用语义分割模型pt,为什么效果反差这么大:
#include <torch/torch.h>
#include <torch/script.h>
#include <iostream>
#include <vector>
#include <string>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include<ctime>
std::string infer(std::string, torch::jit::script::Module);
clock_t start,end;
void Visualization(cv::Mat prediction_map, std::string LUT_file) {
cv::cvtColor(prediction_map.clone(), prediction_map, cv::COLOR_GRAY2BGR);
cv::Mat label_colours = cv