mirror of
https://github.com/lordmathis/CUDANet.git
synced 2025-11-05 17:34:21 +00:00
Export pretrained alexnet
This commit is contained in:
13
examples/alexnet/alexnet.py
Normal file
13
examples/alexnet/alexnet.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import torchvision
|
||||
import sys
|
||||
|
||||
sys.path.append('../../tools') # Ugly hack
|
||||
from utils import export_model_weights, print_model_parameters
|
||||
|
||||
if __name__ == "__main__":
|
||||
alexnet = torchvision.models.alexnet(pretrained=True)
|
||||
print_model_parameters(alexnet) # print layer names and number of parameters
|
||||
export_model_weights(alexnet, 'alexnet_weights.bin')
|
||||
print()
|
||||
print(alexnet)
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#include <model.hpp>
|
||||
#include <conv2d.cuh>
|
||||
|
||||
std::vector<float> readAndNormalizeImage(const std::string& imagePath, int width, int height) {
|
||||
// Read the image using OpenCV
|
||||
@@ -28,6 +29,17 @@ std::vector<float> readAndNormalizeImage(const std::string& imagePath, int width
|
||||
CUDANet::Model* createModel(const int inputSize, const int inputChannels, const int outputSize) {
|
||||
CUDANet::Model *model =
|
||||
new CUDANet::Model(inputSize, inputChannels, outputSize);
|
||||
|
||||
// AlexNet
|
||||
CUDANet::Layers::Conv2d *conv1 = new CUDANet::Layers::Conv2d(
|
||||
inputSize, inputChannels, 11, 4, 96, CUDANet::Layers::Padding::SAME, CUDANet::Layers::ActivationType::RELU
|
||||
);
|
||||
model->addLayer("conv1", conv1);
|
||||
CUDANet::Layers::MaxPooling *pool1 = new CUDANet::Layers::MaxPooling(
|
||||
3, 2
|
||||
)
|
||||
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user