MCPcopy Create free account
hub / github.com/AllentDan/LibtorchTutorials / main

Function main

lesson5-TrainingVGG/main.cpp:6–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include<Classification.h>
5
6int main(int argc, char *argv[])
7{
8 auto pavgpool = torch::nn::AdaptiveAvgPool2d(torch::nn::AdaptiveAvgPool2dOptions(7));
9 auto inp = torch::rand({1,3,7,7});
10 auto outp = pavgpool->forward(inp);
11 std::cout<<outp.sizes();
12 std::vector<int> cfg_dd = {64, 64, -1, 128, 128, -1, 256, 256, 256, -1, 512, 512, 512, -1, 512, 512, 512, -1};
13 auto vgg_dd = VGG(cfg_dd,1000,true);
14 auto in = torch::rand({1,3,224,224});
15 auto dictdd = vgg_dd->named_parameters();
16 vgg_dd->forward(in);
17 for (auto n = dictdd.begin(); n != dictdd.end(); n++)
18 {
19 std::cout<<(*n).key()<<std::endl;
20 }
21
22 std::string vgg_path = "D:\\AllentFiles\\code\\tmp\\vgg16_bn.pt";
23 std::string train_val_dir = "D:\\AllentFiles\\data\\dataset4teach\\hymenoptera_data";
24 Classifier classifier(0);
25 classifier.Initialize(2,vgg_path);
26
27 //predict
28 classifier.LoadWeight("classifer.pt");
29 cv::Mat image = cv::imread(train_val_dir+"\\val\\bees\\2407809945_fb525ef54d.jpg");
30 classifier.Predict(image);
31 classifier.Train(300,4,0.0003,train_val_dir,".jpg","classifer.pt");
32 std::vector<int> cfg_a = {64, -1, 128, -1, 256, 256, -1, 512, 512, -1, 512, 512, -1};
33 std::vector<int> cfg_d = {64, 64, -1, 128, 128, -1, 256, 256, 256, -1, 512, 512, 512, -1, 512, 512, 512, -1};
34 auto vgg = VGG(cfg_d,1000,true);
35 auto dict = vgg->named_parameters();
36 torch::load(vgg, vgg_path);
37 QApplication a(argc, argv);
38 MainWindow w;
39 w.show();
40 return a.exec();
41}

Callers

nothing calls this directly

Calls 8

beginMethod · 0.80
endMethod · 0.80
forwardMethod · 0.45
keyMethod · 0.45
InitializeMethod · 0.45
LoadWeightMethod · 0.45
PredictMethod · 0.45
TrainMethod · 0.45

Tested by

no test coverage detected