Could not find com.android.tools.build:gradle:5.4.1.
Searched in the following locations:
- https://jcenter.bintray.com/com/android/tools/build/gradle/5.4.1/gradle-5.4.1.pom
- https://jcenter.bintray.com/com/android/tools/build/gradle/5.4.1/gradle-5.4.1.jar
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/5.4.1/gradle-5.4.1.pom
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/5.4.1/gradle-5.4.1.jar
Required by:
project :
Add google Maven repository and sync project
Open File
总得来的说就是gradle版本错误,gradle是有两个版本的,一个是插件版本,一个固件版本如下图
如果是版本过低,就更新版本,下面两个链接提供更新方法。下载最新版本放在本地的对应位置然后更新,或者使用编译器提示的直接更新。
参考:
1.https://blog.csdn.net/lili861217/article/details/113357112
2.https://blog.csdn.net/kl1411/article/details/123197159 Android studio
3.https://blog.csdn.net/kmblack1/article/details/123664652
部署yolov5l 6.0时修改了bin和param以及根据premute修改了stride16,32后运行run出现下面问题
Execution failed for task ':app:compressDebugAssets'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CompressAssetsWorkAction
> Java heap space
python export.py --weights weights/yolov5s.pt --include torchscript --train
出现
1.
TorchScript: starting export with torch 1.7.1+cu101...
TorchScript: export failure: save(): incompatible function arguments. The following argument types are supported:
1. (self: torch._C.ScriptModule, filename: str, _extra_files: Dict[str, str] = {}) -> None
Invoked with: <torch._C.ScriptModule object at 0x7f8718f738f0>, PosixPath('weights/yolov5s6.torchscript.pt')
Export complete (2.30s)
在export_torchscript()函数中添加:f = str(f)即可
def export_torchscript(model, im, file, optimize, prefix=colorstr('TorchScript:')):
# YOLOv5 TorchScript model export
try:
print(f'\n{prefix} starting export with torch {torch.__version__}...')
f = file.with_suffix('.torchscript.pt')
f = str(f) # 添加这句 第55行
ts = torch.jit.trace(model, im, strict=False)
(optimize_for_mobile(ts) if optimize else ts).save(f)
print(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)')
except Exception as e:
print(f'{prefix} export failure: {e}')
export: data=data/voc2007.yaml, weights=weights/prune.pt, imgsz=[512, 512], batch_size=1, device=cpu, half=False, inplace=False, train=True, optimize=False, int8=False, dynamic=False, simplify=False, opset=13, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=['torchscript']
YOLOv5 2022-5-18 torch 1.7.1+cu101 CPU
Traceback (most recent call last):
File "/home/yolov5-v6-main/export.py", line 364, in <module>
main(opt)
File "/home/yolov5-v6-main/export.py", line 359, in main
run(**vars(opt))
File "/home/.conda/envs/chen/lib/python3.6/site-packages/torch/autograd/grad_mode.py", line 26, in decorate_context
return func(*args, **kwargs)
File "/home/yolov5-v6-main/export.py", line 277, in run
model = attempt_load(weights, map_location=device, inplace=True, fuse=True) # load FP32 model
File "/home/yolov5-v6-main/models/experimental.py", line 96, in attempt_load
model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval()) # FP32 model
AttributeError: 'collections.OrderedDict' object has no attribute 'float'
训练的模型保存方式的问题
3.
pip install onnx-simplifier
Looking in indexes: https://mirrors.ustc.edu.cn/pypi/web/simple
Collecting onnx-simplifier
Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/aa/dc/7c7a472abda058921ccd681c852f61176be9a54551ceb7dcf64857d45c61/onnx-simplifier-0.3.10.tar.gz (14 kB)
Requirement already satisfied: onnx in /home/chenyuping/.conda/envs/chen/lib/python3.6/site-packages (from onnx-simplifier) (1.10.0)
Collecting onnxoptimizer>=0.2.6
Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/a9/b6/12d1290758e21afae1c94f99d099f07aba8ef0b053850fe562396fac6475/onnxoptimizer-0.2.7-cp36-cp36m-manylinux2014_x86_64.whl (498 kB)
Requirement already satisfied: protobuf>=3.7.0 in /home/chenyuping/.conda/envs/chen/lib/python3.6/site-packages (from onnx-simplifier) (3.14.0)
Collecting rich
Using cached https://mirrors.bfsu.edu.cn/pypi/web/packages/13/3f/1996db12d23733e2834b9c2b094cc59c0d1ab943fedafcdb34b5c0da9ebf/rich-12.4.4-py3-none-any.whl (232 kB)
ERROR: Could not find a version that satisfies the requirement onnxruntime>=1.11.1 (from onnx-simplifier) (from versions: 0.1.2, 0.1.3, 0.1.4, 0.2.1, 0.3.0, 0.4.0, 0.5.0, 1.0.0, 1.1.0, 1.1.1, 1.1.2, 1.2.0, 1.3.0, 1.4.0, 1.5.1, 1.5.2, 1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.9.0, 1.10.0)
ERROR: No matching distribution found for onnxruntime>=1.11.1 (from onnx-simplifier)
试过
pip install -i https://pypi.douban.com/simple -U onnx-simplifier --user
pip3 install onnx-simplifier
pip3 install onnx-simplifier==1.10.0
全都不行,最后是pip3 install onnxruntime
再pip3 install onnx-simplifier
成功的
4.
root@test:/home/test/ncnn-20220420-ubuntu-1804/bin# ./onnx2ncnn yolov5s5_sim.onnx yolov5s5.param yolov5s5.bin
bash: ./onnx2ncnn: Permission denied
是因为文件夹没有授权,切换test用户,然后chomd 777 /home/test/ncnn-20220420-ubuntu-1804/
5.
执行test@test:~/ncnn-master/build/tools/onnx$ ./onnx2ncnn yolov5s5_sim.onnx yolov5s5.param yolov5s5.bin
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice step !
Unsupported slice axes !
Unsupported slice axes !
Unsupported slice axes !
Unsupported slice axes !
Unsupported slice axes !
Unsupported slice axes !
Unsupported slice axes !
Unsupported slice axes !
Unsupported slice axes !
执行test@test:~/ncnn-master/build/tools$ ./ncnnoptimize ./onnx/yolov5s5.param ./onnx/yolov5s5.bin nacnn-opt.param ncnn-opt.bin 1
create_custom_layer YoloV5Focus
parse layer_type failed
load_model error at layer 226, parameter file has inconsistent content.
Segmentation fault (core dumped)
是因为忘了改层数,打开yolov5s5.param,修改。
重新执行test@test:~/ncnn-master/build/tools$ ./ncnnoptimize ./onnx/yolov5s5.param ./onnx/yolov5s5.bin nacnn-opt.param ncnn-opt.bin 1
create_custom_layer YoloV5Focus
eliminate_split images splitncnn_input0
model has custom layer, shape_inference skipped
model has custom layer, estimate_memory_footprint skipped
Segmentation fault (core dumped)
1.python export.py --train --simply --weights best.pt
cd /home/test/ncnn-master/build/tools/onnx/
./onnx2ncnn best.onnx best.param best.bin
1)下载ncnn-yolov5-android源码
下载地址:ncnn-android-yolov5
(2)下载ncnn-android-vulkan包
下载地址: ncnn-releasesncnn-randroid-vulkan.
选择ncnn-xxx-android-vulkan.zip下载,xxx为对应的ncnn版本日期。
将ncnn-xxx-android-vulkan.zip解压到ncnn-yolov5-android的app\src\main\jni路径下
在AS中打开,配置好NDK版本后,编译运行。
1.把best.bin best.param 放入D:\ncnn\ncnn-android-yolov5-master\app\src\main\assets
2.修改 yolov5ncnn_jni.cpp
878对应 453行stride 16 里 ex.extract("878", out);
898对应 472行stride 32 里 ex.extract("898", out);
修改第329行
// init param
{
int ret = yolov5.load_param(mgr, "best.param"); # 329
// int ret = yolov5.load_param(mgr, "yolov5s6.param");
if (ret != 0)
{
__android_log_print(ANDROID_LOG_DEBUG, "YoloV5Ncnn", "load_param failed");
return JNI_FALSE;
}
}
// init bin
{
int ret = yolov5.load_model(mgr, "best.bin"); # 340
// int ret = yolov5.load_model(mgr, "yolov5l6.bin");
if (ret != 0)
{
__android_log_print(ANDROID_LOG_DEBUG, "YoloV5Ncnn", "load_model failed");
return JNI_FALSE;
}
}
修改第524行classname 换成自己的数据集类别,类别顺序不能修改
static const char* class_names[] = {
"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow",
"diningtable", "dog", "horse", "motorbike", "person", "pottedplant",
"sheep", "sofa", "train", "tvmonitor"
};
出现java out of memory heap
把asset里面的其他bin和param都删除了就能运行了