Comments (12)
@caochunyuan 路径没有找到,首先要确定squeezenet_v1.1.bin文件引入到工程中
NSString *paramPath = [[NSBundle mainBundle] pathForResource:@"squeezenet_v1.1" ofType:@"param"];
NSString *binPath = [[NSBundle mainBundle] pathForResource:@"squeezenet_v1.1" ofType:@"bin"];
int r0 = net.load_param([paramPath UTF8String]);
int r1 = net.load_model([binPath UTF8String]);
from ncnn.
这个代码片段可以参考。。。有错误请指出
#include <algorithm>
#include <functional>
#include <vector>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <UIKit/UIImage.h>
// ncnn
#include "net.h"
static int print_topk(const std::vector<float>& cls_scores, int topk)
{
// partial sort topk with index
int size = cls_scores.size();
std::vector< std::pair<float, int> > vec;
vec.resize(size);
for (int i=0; i<size; i++)
{
vec[i] = std::make_pair(cls_scores[i], i);
}
std::partial_sort(vec.begin(), vec.begin() + topk, vec.end(),
std::greater< std::pair<float, int> >());
// print topk and score
for (int i=0; i<topk; i++)
{
float score = vec[i].first;
int index = vec[i].second;
fprintf(stderr, "%d = %f\n", index, score);
}
return 0;
}
int main(int argc, char** argv)
{
const char* imagepath = argv[1];
// load image
UIImage* image = 0;
{
NSString* imagePath = [NSString stringWithUTF8String:imagepath];
image = [UIImage imageWithContentsOfFile:imagePath];
}
// get rgba pixels from image
int w = image.size.width;
int h = image.size.height;
fprintf(stderr, "%d x %d\n", w, h);
unsigned char* rgba = new unsigned char[w*h*4];
{
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
CGContextRef contextRef = CGBitmapContextCreate(rgba, w, h, 8, w*4,
colorSpace,
kCGImageAlphaNoneSkipLast | kCGBitmapByteOrderDefault);
CGContextDrawImage(contextRef, CGRectMake(0, 0, w, h), image.CGImage);
CGContextRelease(contextRef);
}
// init net
ncnn::Net net;
{
int r0 = net.load_param("squeezenet_v1.1.param");
int r1 = net.load_model("squeezenet_v1.1.bin");
fprintf(stderr, "net load %d %d\n", r0, r1);
}
// run forward
ncnn::Mat out;
{
ncnn::Extractor ex = net.create_extractor();
ex.set_light_mode(true);
ex.set_num_threads(2);
ncnn::Mat in = ncnn::Mat::from_pixels_resize(rgba, ncnn::Mat::PIXEL_RGBA2BGR, w, h, 227, 227);
const float mean_vals[3] = {104.f, 117.f, 123.f};
in.substract_mean_normalize(mean_vals, 0);
ex.input("data", in);
ex.extract("prob", out);
}
// get prob
std::vector<float> cls_scores;
{
cls_scores.resize(out.c);
for (int j=0; j<out.c; j++)
{
const float* prob = out.data + out.cstep * j;
cls_scores[j] = prob[0];
}
}
// print topk
print_topk(cls_scores, 3);
// clean
delete[] rgba;
return 0;
}
from ncnn.
@humf 我文件是可以读成功的,通过NSFileHandle check过,但是在net.load_parm这里挂了,你这里ncnn库是他们的release里那到的吗?这里有什么要注意的地方么?
from ncnn.
from ncnn.
用 mm 文件
from ncnn.
非常感谢 @nihui 已在ios上成功跑起来了
from ncnn.
我在ios上跑,会出现这种错误,fopen squeezenet_v1.1.param failed
fopen squeezenet_v1.1.bin failed 什么原因呢
from ncnn.
稀世精品,真的太赞了,服(大写)x100
from ncnn.
https://github.com/dangbo/ncnn-mobile use ncnn in Android and iOS
from ncnn.
我在接入的时候有报错,具体是const float* prob = out.data + out.cstep * j;报错信息是“Semantic Issue Group - Arithmetic on a pointer to void”。可以帮忙解答一下吗?
from ncnn.
我在接入的时候有报错,具体是const float* prob = out.data + out.cstep * j;报错信息是“Semantic Issue Group - Arithmetic on a pointer to void”。可以帮忙解答一下吗?
for (int j=0; j<out.c; j++)
{
cls_scores[j] = out[j];
}
from ncnn.
大神你好,我在用ncnn做人脸检测,最近遇到一个问题,我用UIimage加载iPhone拍的图片,用你的这种方式获取图像数据
unsigned char* rgba = new unsigned char[wh4];
{
CGColorSpaceRef colorSpace = CGImageGetColorSpace(image.CGImage);
CGContextRef contextRef = CGBitmapContextCreate(rgba, w, h, 8, w*4,
colorSpace,
kCGImageAlphaNoneSkipLast | kCGBitmapByteOrderDefault);
CGContextDrawImage(contextRef, CGRectMake(0, 0, w, h), image.CGImage);
CGContextRelease(contextRef);
}
处理结果不对,人脸框是错的。
用cv::Mat imageMat;
UIImageToMat(image,imageMat);
cv::transpose(imageMat, imageMat);
cv::flip(imageMat,imageMat,1);
rgba = imageMat.data
处理结果才是对的,这是为什么呢?大神有遇到过这个问题吗?大神有空帮忙解答一下哈,我是不想借助opencv这种方式获取图像数据。
from ncnn.
Related Issues (20)
- 在64核机器上跑ncnn模型,运行时只会调用其中一个核,设置哪些参数能跑指定数量的cpu核心 HOT 1
- mtcnn ncnn模型fp32转fp16为什么会段错误 HOT 8
- 用摄像头调用 yolov5 net.extractor时内存增长迅速 HOT 1
- MacOS下 new ncnn::Net() 崩溃 HOT 2
- Tile 算子似乎没有起作用
- yolov8训练完成的模型转成ncnn的模型后,推理不出结果,网上查了说要进行前后处理,确实不会,能发个cpp的例子看看么! HOT 4
- ncnn-20240410使用-DNCNN_BF16=OFF编译报错 HOT 3
- rnn(lstm,gru),解卷积的量化以及增加weight only的量化 HOT 1
- 可以给生成的pnnx.py中的pytorch model 增加初始化权重默认入参么,方便迁移到其他地方使用
- 预编译库中,希望能增加macOS下的动态库版本供下载
- [pnnx]:torch.clamp_min convert failed HOT 2
- 目前RISCV版本中用到的RVV intrinsic代码已经不是最新版本了,有升级riscv intrinsic代码的计划吗?
- Android下的build,为什么默认关闭exception呢? HOT 5
- openmp冲突引起crash
- iPhone创建ncnn::net崩溃 HOT 2
- benchmark测试占用率低
- 手动创建的net,推理慢了很多
- yolov8n模型在鲲鹏ARM机器的检测结果和pytorch结果不一样 HOT 6
- 我有3个GPU,但get_gpu_count()=1 HOT 8
- pnnx和ncnn输出不一致
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ncnn.