国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

TensorRT(C++)基礎(chǔ)代碼解析

這篇具有很好參考價值的文章主要介紹了TensorRT(C++)基礎(chǔ)代碼解析。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

TensorRT(C++)基礎(chǔ)代碼解析



前言


一、TensorRT工作流程

TensorRT(C++)基礎(chǔ)代碼解析,YOLO人員檢測--模型訓練部署,c++,開發(fā)語言

TensorRT(C++)基礎(chǔ)代碼解析,YOLO人員檢測--模型訓練部署,c++,開發(fā)語言

二、C++ API

2.1 構(gòu)建階段

TensorRT build engine的過程

  1. 創(chuàng)建builder
  2. 創(chuàng)建網(wǎng)絡(luò)定義:builder —> network
  3. 配置參數(shù):builder —> config
  4. 生成engine:builder —> engine (network, config)
  5. 序列化保存:engine —> serialize
  6. 釋放資源:delete

2.1.1 創(chuàng)建builder

nvinfer1 是 NVIDIA TensorRT 的 C++ 接口命名空間。構(gòu)建階段的最高級別接口是 Builder。Builder負責優(yōu)化一個模型,并產(chǎn)生Engine。通過如下接口創(chuàng)建一個Builder。

nvinfer1::IBuilder *builder = nvinfer1::createInferBuilder(logger);

2.1.2 創(chuàng)建網(wǎng)絡(luò)定義

NetworkDefinition接口被用來定義模型。接口createNetworkV2接受配置參數(shù),參數(shù)用按位標記的方式傳入。比如上面激活explicitBatch,是通過1U << static_cast<uint32_t (nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH); 將explicitBatch對應(yīng)的配置位設(shè)置為1實現(xiàn)的。在新版本中,請使用createNetworkV2而非其他任何創(chuàng)建NetworkDefinition 的接口。

auto explicitBatch = 1U << static_cast<uint32_t
(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
    // 調(diào)用createNetworkV2創(chuàng)建網(wǎng)絡(luò)定義,參數(shù)是顯性batch
nvinfer1::INetworkDefinition *network = builder->createNetworkV2(explicitBatch);

2.1.3 定義網(wǎng)絡(luò)結(jié)構(gòu)

將模型轉(zhuǎn)移到TensorRT的最常見的方式是以O(shè)NNX格式從框架中導出(將在后續(xù)課程進行介紹),并使用TensorRT的ONNX解析器來填充網(wǎng)絡(luò)定義。同時,也可以使用TensorRT的Layer和Tensor等接口一步一步地進行定義。通過接口來定義網(wǎng)絡(luò)的代碼示例如下:

添加輸入層

const int input_size = 3;
nvinfer1::ITensor *input = network->addInput("data", nvinfer1::DataType::kFLOAT,nvinfer1::Dims4{1, input_size, 1, 1}) 		 

添加全連接層

nvinfer1::IFullyConnectedLayer* fc1 = network->addFullyConnected(*input, output_size, fc1w, fc1b);

添加激活層

nvinfer1::IActivationLayer* relu1 = network->addActivation(*fc1->getOutput(0), nvinfer1::ActivationType::kRELU);

2.1.4 定義網(wǎng)絡(luò)輸入輸出

定義哪些張量是網(wǎng)絡(luò)的輸入和輸出。沒有被標記為輸出的張量被認為是瞬時值,可以被構(gòu)建者優(yōu)化掉。輸入和輸出張量必須被命名,以便在運行時,TensorRT知道如何將輸入和輸出緩沖區(qū)綁定到模型上。

// 設(shè)置輸出名字
sigmoid->getOutput(0)->setName("output");
// 標記輸出,沒有標記會被當成順時針優(yōu)化掉
network->markOutput(*sigmoid->getOutput(0));

2.1.5 配置參數(shù)

添加相關(guān)Builder 的配置。createBuilderConfig接口被用來指定TensorRT應(yīng)該如何優(yōu)化模型

 nvinfer1::IBuilderConfig *config = builder->createBuilderConfig();
 // 設(shè)置最大工作空間大小,單位是字節(jié)
config->setMaxWorkspaceSize(1 << 28); // 256MiB

2.1.6 生成Engine

 nvinfer1::ICudaEngine *engine = builder->buildEngineWithConfig(*network, *config);

2.1.7 保存為模型文件

nvinfer1::IHostMemory *serialized_engine = engine->serialize();
    // 存入文件
std::ofstream outfile("model/mlp.engine", std::ios::binary);
assert(outfile.is_open() && "Failed to open file for writing");
outfile.write((char *)serialized_engine->data(), serialized_engine->size());

2.1.8 釋放資源

outfile.close();
delete serialized_engine;
delete engine;
delete config;
delete network;

完整代碼

/*
TensorRT build engine的過程
7. 創(chuàng)建builder
8. 創(chuàng)建網(wǎng)絡(luò)定義:builder ---> network
9. 配置參數(shù):builder ---> config
10. 生成engine:builder ---> engine (network, config)
11. 序列化保存:engine ---> serialize
12. 釋放資源:delete
*/

#include <iostream>
#include <fstream>
#include <cassert>
#include <vector>

#include <NvInfer.h>

// logger用來管控打印日志級別
// TRTLogger繼承自nvinfer1::ILogger
class TRTLogger : public nvinfer1::ILogger
{
    void log(Severity severity, const char *msg) noexcept override
    {
        // 屏蔽INFO級別的日志
        if (severity != Severity::kINFO)
            std::cout << msg << std::endl;
    }
} gLogger;

// 保存權(quán)重
void saveWeights(const std::string &filename, const float *data, int size)
{
    std::ofstream outfile(filename, std::ios::binary);
    assert(outfile.is_open() && "save weights failed");  // assert斷言,如果條件不滿足,就會報錯
    outfile.write((char *)(&size), sizeof(int));         // 保存權(quán)重的大小
    outfile.write((char *)(data), size * sizeof(float)); // 保存權(quán)重的數(shù)據(jù)
    outfile.close();
}
// 讀取權(quán)重
std::vector<float> loadWeights(const std::string &filename)
{
    std::ifstream infile(filename, std::ios::binary);
    assert(infile.is_open() && "load weights failed");
    int size;
    infile.read((char *)(&size), sizeof(int));                // 讀取權(quán)重的大小
    std::vector<float> data(size);                            // 創(chuàng)建一個vector,大小為size
    infile.read((char *)(data.data()), size * sizeof(float)); // 讀取權(quán)重的數(shù)據(jù)
    infile.close();
    return data;
}

int main()
{
    // ======= 1. 創(chuàng)建builder =======
    TRTLogger logger;
    nvinfer1::IBuilder *builder = nvinfer1::createInferBuilder(logger);

    // ======= 2. 創(chuàng)建網(wǎng)絡(luò)定義:builder ---> network =======

    // 顯性batch
    // 1 << 0 = 1,二進制移位,左移0位,相當于1(y左移x位,相當于y乘以2的x次方)
    auto explicitBatch = 1U << static_cast<uint32_t>(nvinfer1::NetworkDefinitionCreationFlag::kEXPLICIT_BATCH);
    // 調(diào)用createNetworkV2創(chuàng)建網(wǎng)絡(luò)定義,參數(shù)是顯性batch
    nvinfer1::INetworkDefinition *network = builder->createNetworkV2(explicitBatch);

    // 定義網(wǎng)絡(luò)結(jié)構(gòu)
    // mlp多層感知機:input(1,3,1,1) --> fc1 --> sigmoid --> output (2)

    // 創(chuàng)建一個input tensor ,參數(shù)分別是:name, data type, dims
    const int input_size = 3;
    nvinfer1::ITensor *input = network->addInput("data", nvinfer1::DataType::kFLOAT, nvinfer1::Dims4{1, input_size, 1, 1});

    // 創(chuàng)建全連接層fc1
    // weight and bias
    const float *fc1_weight_data = new float[input_size * 2]{0.1, 0.2, 0.3, 0.4, 0.5, 0.6};
    const float *fc1_bias_data = new float[2]{0.1, 0.5};

    // 將權(quán)重保存到文件中,演示從別的來源加載權(quán)重
    saveWeights("model/fc1.wts", fc1_weight_data, 6);
    saveWeights("model/fc1.bias", fc1_bias_data, 2);

    // 讀取權(quán)重
    auto fc1_weight_vec = loadWeights("model/fc1.wts");
    auto fc1_bias_vec = loadWeights("model/fc1.bias");

    // 轉(zhuǎn)為nvinfer1::Weights類型,參數(shù)分別是:data type, data, size
    nvinfer1::Weights fc1_weight{nvinfer1::DataType::kFLOAT, fc1_weight_vec.data(), fc1_weight_vec.size()};
    nvinfer1::Weights fc1_bias{nvinfer1::DataType::kFLOAT, fc1_bias_vec.data(), fc1_bias_vec.size()};

    const int output_size = 2;
    // 調(diào)用addFullyConnected創(chuàng)建全連接層,參數(shù)分別是:input tensor, output size, weight, bias
    nvinfer1::IFullyConnectedLayer *fc1 = network->addFullyConnected(*input, output_size, fc1_weight, fc1_bias);

    // 添加sigmoid激活層,參數(shù)分別是:input tensor, activation type(激活函數(shù)類型)
    nvinfer1::IActivationLayer *sigmoid = network->addActivation(*fc1->getOutput(0), nvinfer1::ActivationType::kSIGMOID);

    // 設(shè)置輸出名字
    sigmoid->getOutput(0)->setName("output");
    // 標記輸出,沒有標記會被當成順時針優(yōu)化掉
    network->markOutput(*sigmoid->getOutput(0));

    // 設(shè)定最大batch size
    builder->setMaxBatchSize(1);

    // ====== 3. 配置參數(shù):builder ---> config ======
    // 添加配置參數(shù),告訴TensorRT應(yīng)該如何優(yōu)化網(wǎng)絡(luò)
    nvinfer1::IBuilderConfig *config = builder->createBuilderConfig();
    // 設(shè)置最大工作空間大小,單位是字節(jié)
    config->setMaxWorkspaceSize(1 << 28); // 256MiB

    // ====== 4. 創(chuàng)建engine:builder ---> network ---> config ======
    nvinfer1::ICudaEngine *engine = builder->buildEngineWithConfig(*network, *config);
    if (!engine)
    {
        std::cerr << "Failed to create engine!" << std::endl;
        return -1;
    }
    // ====== 5. 序列化engine ======
    nvinfer1::IHostMemory *serialized_engine = engine->serialize();
    // 存入文件
    std::ofstream outfile("model/mlp.engine", std::ios::binary);
    assert(outfile.is_open() && "Failed to open file for writing");
    outfile.write((char *)serialized_engine->data(), serialized_engine->size());

    

    // ====== 6. 釋放資源 ======
    // 理論上,這些資源都會在程序結(jié)束時自動釋放,但是為了演示,這里手動釋放部分
    outfile.close();

    delete serialized_engine;
    delete engine;
    delete config;
    delete network;
    delete builder;

    std::cout << "engine文件生成成功!" << std::endl;

    return 0;
}

2.2 運行期

TensorRT(C++)基礎(chǔ)代碼解析,YOLO人員檢測--模型訓練部署,c++,開發(fā)語言
TensorRT runtime 推理過程

  1. 創(chuàng)建一個runtime對象
  2. 反序列化生成engine:runtime —> engine
  3. 創(chuàng)建一個執(zhí)行上下文ExecutionContext:engine —> context
  4. 填充數(shù)據(jù)
  5. 執(zhí)行推理:context —> enqueueV2
  6. 釋放資源:delete

2.2.1 創(chuàng)建一個runtime對象

TensorRT運行時的最高層級接口是Runtime

 nvinfer1::IRuntime *runtime = nvinfer1::createInferRuntime(logger);

2.2.2 反序列化生成engine

通過讀取模型文件并反序列化,我們可以利用runtime生成Engine。

nvinfer1::ICudaEngine *engine = runtime->deserializeCudaEngine(engine_data.data(), engine_data.size(), nullptr);

2.2.3 創(chuàng)建一個執(zhí)行上下文ExecutionContext

從Engine創(chuàng)建的ExecutionContext接口是調(diào)用推理的主要接口。ExecutionContext包含與特定調(diào)用相關(guān)的所有狀態(tài),因此可以有多個與單個引擎相關(guān)的上下文,且并行運行它們。

nvinfer1::IExecutionContext *context = engine->createExecutionContext();

2.2.4 為推理填充輸入

首先創(chuàng)建CUDA Stream用于推理的執(zhí)行。

cudaStream_t stream = nullptr;
cudaStreamCreate(&stream);

同時在CPU和GPU上分配輸入輸出內(nèi)存,并將輸入數(shù)據(jù)從CPU拷貝到GPU上。

// 輸入數(shù)據(jù)
float* h_in_data = new float[3]{1.4, 3.2, 1.1};
int in_data_size = sizeof(float) * 3;
float* d_in_data = nullptr;
// 輸出數(shù)據(jù)
float* h_out_data = new float[2]{0.0, 0.0};
int out_data_size = sizeof(float) * 2;
float* d_out_data = nullptr;
// 申請GPU上的內(nèi)存
cudaMalloc(&d_in_data, in_data_size);
cudaMalloc(&d_out_data, out_data_size);
// 拷貝數(shù)據(jù)
cudaMemcpyAsync(d_in_data, h_in_data, in_data_size, cudaMemcpyHostToDevice, stream);
// enqueueV2中是把輸入輸出的內(nèi)存地址放到bindings這個數(shù)組中,需要寫代碼時確定這些輸入輸出的順序(這樣容易出錯,而且不好定位bug,所以新的接口取消了這樣的方式,不過目前很多官方 sample 也在用v2)
float* bindings[] = {d_in_data, d_out_data};

2.2.4 調(diào)用enqueueV2來執(zhí)行推理

bool success = context -> enqueueV2((void **) bindings, stream, nullptr);
// 數(shù)據(jù)從device --> host
cudaMemcpyAsync(host_output_data, device_output_data, output_data_size, cudaMemcpyDeviceToHost, stream);
// 等待流執(zhí)行完畢
cudaStreamSynchronize(stream);
// 輸出結(jié)果
std::cout << "輸出結(jié)果: " << host_output_data[0] << " " << host_output_data[1] << std::endl;

2.2.5 釋放資源

cudaStreamDestroy(stream);
cudaFree(device_input_data_address);
cudaFree(device_output_data_address);   
delete[] host_input_data;
delete[] host_output_data;

delete context;
delete engine;
delete runtime;

完整代碼

/*
使用.cu是希望使用CUDA的編譯器NVCC,會自動連接cuda庫

TensorRT runtime 推理過程

1. 創(chuàng)建一個runtime對象
2. 反序列化生成engine:runtime ---> engine
3. 創(chuàng)建一個執(zhí)行上下文ExecutionContext:engine ---> context

    4. 填充數(shù)據(jù)
    5. 執(zhí)行推理:context ---> enqueueV2

6. 釋放資源:delete

*/
#include <iostream>
#include <vector>
#include <fstream>
#include <cassert>

#include "cuda_runtime.h"
#include "NvInfer.h"

// logger用來管控打印日志級別
// TRTLogger繼承自nvinfer1::ILogger
class TRTLogger : public nvinfer1::ILogger
{
    void log(Severity severity, const char *msg) noexcept override
    {
        // 屏蔽INFO級別的日志
        if (severity != Severity::kINFO)
            std::cout << msg << std::endl;
    }
} gLogger;

// 加載模型
std::vector<unsigned char> loadEngineModel(const std::string &fileName)
{
    std::ifstream file(fileName, std::ios::binary);        // 以二進制方式讀取
    assert(file.is_open() && "load engine model failed!"); // 斷言

    file.seekg(0, std::ios::end); // 定位到文件末尾
    size_t size = file.tellg();   // 獲取文件大小

    std::vector<unsigned char> data(size); // 創(chuàng)建一個vector,大小為size
    file.seekg(0, std::ios::beg);          // 定位到文件開頭
    file.read((char *)data.data(), size);  // 讀取文件內(nèi)容到data中
    file.close();

    return data;
}

int main()
{
    // ==================== 1. 創(chuàng)建一個runtime對象 ====================
    TRTLogger logger;
    nvinfer1::IRuntime *runtime = nvinfer1::createInferRuntime(logger);

    // ==================== 2. 反序列化生成engine ====================
    // 讀取文件
    auto engineModel = loadEngineModel("./model/mlp.engine");
    // 調(diào)用runtime的反序列化方法,生成engine,參數(shù)分別是:模型數(shù)據(jù)地址,模型大小,pluginFactory
    nvinfer1::ICudaEngine *engine = runtime->deserializeCudaEngine(engineModel.data(), engineModel.size(), nullptr);

    if (!engine)
    {
        std::cout << "deserialize engine failed!" << std::endl;
        return -1;
    }

    // ==================== 3. 創(chuàng)建一個執(zhí)行上下文 ====================
    nvinfer1::IExecutionContext *context = engine->createExecutionContext();

    // ==================== 4. 填充數(shù)據(jù) ====================

    // 設(shè)置stream 流
    cudaStream_t stream = nullptr;
    cudaStreamCreate(&stream);

    // 數(shù)據(jù)流轉(zhuǎn):host --> device ---> inference ---> host

    // 輸入數(shù)據(jù)
    float *host_input_data = new float[3]{2, 4, 8}; // host 輸入數(shù)據(jù)
    int input_data_size = 3 * sizeof(float);        // 輸入數(shù)據(jù)大小
    float *device_input_data = nullptr;             // device 輸入數(shù)據(jù)

    // 輸出數(shù)據(jù)
    float *host_output_data = new float[2]{0, 0}; // host 輸出數(shù)據(jù)
    int output_data_size = 2 * sizeof(float);     // 輸出數(shù)據(jù)大小
    float *device_output_data = nullptr;          // device 輸出數(shù)據(jù)

    // 申請device內(nèi)存
    cudaMalloc((void **)&device_input_data, input_data_size);
    cudaMalloc((void **)&device_output_data, output_data_size);

    // host --> device
    // 參數(shù)分別是:目標地址,源地址,數(shù)據(jù)大小,拷貝方向
    cudaMemcpyAsync(device_input_data, host_input_data, input_data_size, cudaMemcpyHostToDevice, stream);

    // bindings告訴Context輸入輸出數(shù)據(jù)的位置
    float *bindings[] = {device_input_data, device_output_data};

    // ==================== 5. 執(zhí)行推理 ====================
    bool success = context -> enqueueV2((void **) bindings, stream, nullptr);
    // 數(shù)據(jù)從device --> host
    cudaMemcpyAsync(host_output_data, device_output_data, output_data_size, cudaMemcpyDeviceToHost, stream);
    // 等待流執(zhí)行完畢
    cudaStreamSynchronize(stream);
    // 輸出結(jié)果
    std::cout << "輸出結(jié)果: " << host_output_data[0] << " " << host_output_data[1] << std::endl;

    // ==================== 6. 釋放資源 ====================
    cudaStreamDestroy(stream);
    cudaFree(device_input_data); 
    cudaFree(device_output_data);

    delete host_input_data;
    delete host_output_data;

    delete context;
    delete engine;
    delete runtime;
    
    return 0;
}

總結(jié)

TensorRT(C++)基礎(chǔ)代碼解析文章來源地址http://www.zghlxwxcb.cn/news/detail-799934.html

到了這里,關(guān)于TensorRT(C++)基礎(chǔ)代碼解析的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 【YOLO】Windows 下 YOLOv8 使用 TensorRT 進行模型加速部署

    【YOLO】Windows 下 YOLOv8 使用 TensorRT 進行模型加速部署

    本文全文參考文章為 win10下 yolov8 tensorrt模型加速部署【實戰(zhàn)】 本文使用的代碼倉庫為 TensorRT-Alpha 注:其他 Yolov8 TensorRT 部署項目:YOLOv8 Tensorrt Python/C++部署教程 安裝Visual Studio 2019或者Visual Studio 2022、Nvidia驅(qū)動 安裝cuda,cudnn、opencv、tensorrt并進行相應(yīng)的環(huán)境配置,這里不做配

    2024年02月11日
    瀏覽(25)
  • 改進的yolov5目標檢測-yolov5替換骨干網(wǎng)絡(luò)-yolo剪枝(TensorRT及NCNN部署)

    改進的yolov5目標檢測-yolov5替換骨干網(wǎng)絡(luò)-yolo剪枝(TensorRT及NCNN部署)

    2022.10.30 復(fù)現(xiàn)TPH-YOLOv5 2022.10.31 完成替換backbone為Ghostnet 2022.11.02 完成替換backbone為Shufflenetv2 2022.11.05 完成替換backbone為Mobilenetv3Small 2022.11.10 完成EagleEye對YOLOv5系列剪枝支持 2022.11.14 完成MQBench對YOLOv5系列量化支持 2022.11.16 完成替換backbone為EfficientNetLite-0 2022.11.26 完成替換backbone為

    2024年01月17日
    瀏覽(28)
  • 模型訓練之train.py代碼解析

    作者:安靜到無聲 個人主頁 這段代碼使用了Python 2.x的__future__模塊來導入Python 3.x的一些特性。在Python 2.x中,使用print語句來輸出內(nèi)容,而在Python 3.x中,print語句被變成了print()函數(shù)。因此,在Python 2.x中,如果要使用print()函數(shù)來輸出內(nèi)容,就需要導入__future__模塊中的print_fun

    2024年02月14日
    瀏覽(21)
  • YOLO訓練得到權(quán)重后無法檢測detect目標

    YOLO訓練得到權(quán)重后無法檢測detect目標

    通過自己制造數(shù)據(jù)集,跑完train.py文件后,得到自己的權(quán)重文件 將權(quán)重文件帶入detect.py文件中,發(fā)現(xiàn)可以運行,但是無法識別圖片和視頻中的目標 3.opencv-python版本太高了,看了一眼,果然版本都到4.6了,猜想opencv-python版本問題,結(jié)果——還是不行 https://blog.csdn.net/adai5210/ar

    2024年02月12日
    瀏覽(60)
  • 論文代碼學習—HiFi-GAN(4)——模型訓練函數(shù)train文件具體解析

    論文代碼學習—HiFi-GAN(4)——模型訓練函數(shù)train文件具體解析

    這里翻譯了HiFi-GAN這篇論文的具體內(nèi)容,具體鏈接。 這篇文章還是學到了很多東西,從整體上說,學到了生成對抗網(wǎng)絡(luò)的構(gòu)建思路,包括生成器和鑒定器。細化到具體實現(xiàn)的細節(jié),如何 實現(xiàn)對于特定周期的數(shù)據(jù)處理?在細化,膨脹卷積是如何實現(xiàn)的?這些通過文章,僅僅是了

    2024年02月14日
    瀏覽(23)
  • 【深度學習】YOLOv5實例分割 數(shù)據(jù)集制作、模型訓練以及TensorRT部署

    【深度學習】YOLOv5實例分割 數(shù)據(jù)集制作、模型訓練以及TensorRT部署

    yolov5-seg:官方地址:https://github.com/ultralytics/yolov5/tree/v6.2 TensorRT:8.x.x 語言:C++ 系統(tǒng):ubuntu18.04 前言:由于yolo倉中提供了標準coco的json文件轉(zhuǎn)txt代碼,因此需要將labelme的json文件轉(zhuǎn)為coco json. labelme JSON 轉(zhuǎn)COCO JSON 使用labelme的CreatePolygons按鈕開始繪制多邊形,然后保存為json格式。

    2024年02月06日
    瀏覽(28)
  • 解決yolo3目標檢測訓練過程中train.py運行問題

    yolo3是一種廣泛使用的目標檢測算法,它在計算機視覺領(lǐng)域具有很高的準確率和性能。然而,在使用yolo3進行目標檢測訓練時,有時會出現(xiàn)train.py運行問題。本文將探討如何解決這個問題。 首先,讓我們了解一下訓練過程中可能遇到的常見問題: 缺少依賴項:運行train.py之前,

    2024年02月15日
    瀏覽(24)
  • 用自己的數(shù)據(jù)集訓練YOLO-NAS目標檢測器

    用自己的數(shù)據(jù)集訓練YOLO-NAS目標檢測器

    YOLO-NAS 是 Deci 開發(fā)的一種新的最先進的目標檢測模型。 在本指南中,我們將討論什么是 YOLO-NAS 以及如何在自定義數(shù)據(jù)集上訓練 YOLO-NAS 模型。 在線工具推薦: Three.js AI紋理開發(fā)包 - YOLO合成數(shù)據(jù)生成器 - GLTF/GLB在線編輯 - 3D模型格式在線轉(zhuǎn)換 - 3D場景編輯器 為了訓練我們的自定

    2024年02月05日
    瀏覽(19)
  • LLMs之Chinese-LLaMA-Alpaca-2:源碼解讀(run_clm_sft_with_peft.py文件)—模型訓練前置工作(參數(shù)解析+配置日志)→模型初始化(檢測是否存在訓練過的che

    LLMs之Chinese-LLaMA-Alpaca-2:源碼解讀(run_clm_sft_with_peft.py文件)—模型訓練前置工作(參數(shù)解析+配置日志)→模型初始化(檢測是否存在訓練過的checkpoint+加載預(yù)訓練模型和tokenizer)→數(shù)據(jù)預(yù)處理(監(jiān)督式任務(wù)的數(shù)據(jù)收集器+指令數(shù)據(jù)集【json格式】)→優(yōu)化模型配置(量化模塊+匹配模型voca

    2024年02月06日
    瀏覽(24)
  • LLMs之Chinese-LLaMA-Alpaca-2:源碼解讀(run_clm_pt_with_peft.py文件)—模型訓練前置工作(參數(shù)解析+配置日志)→模型初始化(檢測是否存在訓練過的chec

    LLMs之Chinese-LLaMA-Alpaca-2:源碼解讀(run_clm_pt_with_peft.py文件)—模型訓練前置工作(參數(shù)解析+配置日志)→模型初始化(檢測是否存在訓練過的checkpoint+加載預(yù)訓練模型和tokenizer)→數(shù)據(jù)預(yù)處理(處理【標記化+分塊】+切分txt數(shù)據(jù)集)→優(yōu)化模型配置( 量化模塊 +匹配模型vocabulary大小與to

    2024年02月07日
    瀏覽(29)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包