Nmsl2.cpp 1.84 KB
Newer Older
Nianchen Deng's avatar
Nianchen Deng committed
1
2
3
#include "Nmsl2.h"
#include <time.h>

Nianchen Deng's avatar
sync    
Nianchen Deng committed
4
5
6
7
8
9
10
11
Nmsl2::Nmsl2(int batchSize, int samples)
    : batchSize(batchSize),
      samples(samples),
      resRaw1(nullptr),
      resRaw2(nullptr),
      fcNet1(nullptr),
      fcNet2(nullptr),
      catNet(nullptr) {}
Nianchen Deng's avatar
Nianchen Deng committed
12

Nianchen Deng's avatar
sync    
Nianchen Deng committed
13
14
15
16
17
18
19
20
21
22
bool Nmsl2::load(const std::string &netDir) {
    fcNet1 = new Net();
    fcNet2 = new Net();
    catNet = new Net();
    if (!fcNet1->load(netDir + "fc1.trt") || !fcNet2->load(netDir + "fc2.trt") ||
        !catNet->load(netDir + "cat.trt"))
        return false;
    resRaw1 = sptr<Resource>(new CudaBuffer(batchSize * samples / 2 * sizeof(float4)));
    resRaw2 = sptr<Resource>(new CudaBuffer(batchSize * samples / 2 * sizeof(float4)));
    return true;
Nianchen Deng's avatar
Nianchen Deng committed
23
24
}

Nianchen Deng's avatar
sync    
Nianchen Deng committed
25
26
27
28
29
30
31
32
33
void Nmsl2::bindResources(Resource *resEncoded, Resource *resDepths, Resource *resColors) {
    fcNet1->bindResource("Encoded", resEncoded);
    fcNet1->bindResource("Raw", resRaw1.get());
    fcNet2->bindResource("Encoded", resEncoded);
    fcNet2->bindResource("Raw", resRaw2.get());
    catNet->bindResource("Raw1", resRaw1.get());
    catNet->bindResource("Raw2", resRaw2.get());
    catNet->bindResource("Depths", resDepths);
    catNet->bindResource("Colors", resColors);
Nianchen Deng's avatar
Nianchen Deng committed
34
35
}

Nianchen Deng's avatar
sync    
Nianchen Deng committed
36
37
38
39
40
41
42
43
44
bool Nmsl2::infer() {
    // CudaStream stream1, stream2;
    if (!fcNet1->infer())
        return false;
    if (!fcNet2->infer())
        return false;
    if (!catNet->infer())
        return false;
    return true;
Nianchen Deng's avatar
Nianchen Deng committed
45
46
}

Nianchen Deng's avatar
sync    
Nianchen Deng committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
void Nmsl2::dispose() {
    if (fcNet1 != nullptr) {
        fcNet1->dispose();
        delete fcNet1;
        fcNet1 = nullptr;
    }
    if (fcNet2 != nullptr) {
        fcNet2->dispose();
        delete fcNet2;
        fcNet2 = nullptr;
    }
    if (catNet != nullptr) {
        catNet->dispose();
        delete catNet;
        catNet = nullptr;
    }
    resRaw1 = nullptr;
    resRaw2 = nullptr;
Nianchen Deng's avatar
Nianchen Deng committed
65
}