1.數(shù)據(jù)集標(biāo)注
a.采用VoTT用于圖像檢測(cè)任務(wù)的數(shù)據(jù)集制作voc格式
2.lmdb數(shù)據(jù)集制作
a.采用 weiliu89中的./data/VOC0712/create_list.sh和./data/VOC0712/create_data.sh
腳本制作數(shù)據(jù)集,工程位于本機(jī)ssd/caffe中,以下幾個(gè)文件需要根據(jù)個(gè)人情況修改谭溉。
scripts/create_annoset.py examples/ssd/ssd_pascal.py examples/ssd/score_ssd_pascal.py
指定caffe安裝路徑
caffe_root = '/home/ljg/ssd/caffe'
import os
os.chdir(caffe_root)
import sys
sys.path.insert(0, 'python')
sys.path.insert(0,caffe_root+'python')
把指定gpu訓(xùn)練的注釋掉
還有一些設(shè)置可以參考以下博客
Caffe上用SSD訓(xùn)練和測(cè)試自己的數(shù)據(jù)
SSD框架訓(xùn)練自己的數(shù)據(jù)集
在$CAFFE_ROOT目錄下分別運(yùn)行:
./data/ljy_test/create_list_indoor.sh
./data/ljy_test/create_data_indoor.sh
3.模型訓(xùn)練
chuanqi305/MobileNet-SSD
基于自制數(shù)據(jù)集的MobileNet-SSD模型訓(xùn)練
按照訓(xùn)練步驟訓(xùn)練
4.移植到移動(dòng)端
Ncnn使用詳解(1)——PC端
使用ncnn部署到ios手機(jī)端
android ios 預(yù)編譯庫(kù) 20180129 f133729
我使用的是這個(gè)ncnn庫(kù)文件
之前的版本對(duì)于訓(xùn)練的模型有些層不支持蚕钦,之后的一個(gè)版本對(duì)同樣的圖片輸入結(jié)果不一樣,應(yīng)該是存在bug
dangbo/ncnn-mobile
這是我使用的demoios工程旁钧,我在他的基礎(chǔ)上進(jìn)行啦修改,替換ncnn庫(kù)和相應(yīng)的頭文件,然后還要修改為支持視頻實(shí)時(shí)檢測(cè)
AVCaptureConnection* videoConnection = [videoDataOutput connectionWithMediaType:AVMediaTypeVideo];
[videoConnection setVideoOrientation:AVCaptureVideoOrientationPortrait];
我這個(gè)是采用前置攝像頭拍攝冒掌,要如此設(shè)置,否則圖片是橫著的蹲盘,檢測(cè)出錯(cuò)
Object object;
object.class_id = values[0];
object.prob = values[1];
std::string label = std::string(class_names[object.class_id]);
object.lable = [NSString stringWithUTF8String:label.c_str()];
object.rec.x =(1 - values[2]) * screenW;
object.rec.y = values[3] * screenH;
object.rec.width = (1-values[4]) * screenW- object.rec.x;
object.rec.height = values[5] * screenH - object.rec.y;
objects.push_back(object);
要實(shí)時(shí)在手機(jī)屏幕顯示標(biāo)注框股毫,如上修改
- (void)captureOutput:(AVCaptureOutput*)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection*)connection
{
@autoreleasepool {
CFRetain(sampleBuffer);
UIImage *image =[self imageFromSampleBuffer:sampleBuffer];
CFRelease(sampleBuffer);
[self predictFrameImage:image];
}
}
我把sampleBuffer先轉(zhuǎn)化為image,然后再預(yù)測(cè)召衔,這是取巧的方法皇拣,并不是合理的方法
- (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer
{
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the pixel buffer
void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
// Get the number of bytes per row for the pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
// Get the pixel buffer width and height
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t height = CVPixelBufferGetHeight(imageBuffer);
// Create a device-dependent RGB color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
// Create a bitmap graphics context with the sample buffer data
CGContextRef context = CGBitmapContextCreate(baseAddress, width, height, 8,
bytesPerRow, colorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst);
// Create a Quartz image from the pixel data in the bitmap graphics context
CGImageRef quartzImage = CGBitmapContextCreateImage(context);
// Unlock the pixel buffer
CVPixelBufferUnlockBaseAddress(imageBuffer,0);
// Free up the context and color space
CGContextRelease(context);
CGColorSpaceRelease(colorSpace);
// Create an image object from the Quartz image
//UIImage *image = [UIImage imageWithCGImage:quartzImage];
UIImage *image = [UIImage imageWithCGImage:quartzImage scale:1.0f orientation:UIImageOrientationRight];
// Release the Quartz image
CGImageRelease(quartzImage);
return (image);
}