Ubuntu 20.04上Android NDK编译FFmpeg 5.1全程笔记

Ubuntu 环境下 Android NDK 的安装与配置 1.安装Ubuntu 微软商店(Microsoft Store)中搜索ubuntu,找到对应版本进行下载并安装。 详细安装过程请参考: https://blog.csdn.net/sun___shy/article/details/80917092?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164572002716780269880809%2522%252C%2522scm%2522%253A%252220140713.13010. 阅读详情
AI摘要

本文详细介绍了如何在Linux环境下安装必要的库,如Clang和NASM,然后通过Git克隆FFmpeg源码,切换至特定版本,以及使用AndroidNDK进行64位和32位的交叉编译。文章还提供了配置脚本和CMakeLists示例,展示了如何在AndroidStudio中使用FFmpeg库进行应用开发。,

安装好相关的库

sudo apt install clang
sudo apt-get install yasm
如果不安装上面两个库可能会报类似如下的错:
clang is unable to create an executable file
clang: not found
nasm: not found

下载FFmpeg相关源码:

git clone https://gitee.com/mirrors/ffmpeg/

切换一下相关的分支为5.1的:
git checkout -b remotes/origin/release/5.1 remotes/origin/release/5.1

准备好相关的ndk的开发包android-ndk-r22b-linux-x86_64.zip:
https://dl.google.com/android/repository/android-ndk-r22b-linux-x86_64.zip
android-ndk-r22b-linux-x86_64.zip

然后对它进行解压既可以,这里也可以使用as自带的版本,或者不是ndk的r22版本试试,最好就下载和这里一样的版本

准备编译的config脚本arm64位和32:

#!/bin/bash
#这个API其实写其他版本也可以的,这里先写个21
API=21
#arm64  x86 x86_64 <----> aarch64  i686  x86_64
ARCH=arm64
ARCH2=aarch64
#编译的so输出路径    
PREFIX=/home/test/ffmpeg_64/out/
#此处路径替换为当前NDK路径
TOOLCHAIN=/home/test/Downloads/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64

build()
{
    #配置各个开关选项及NDK相关的工具链路径等
    ./configure \
    --prefix=$PREFIX \
    --disable-static \
    --enable-shared \
    --enable-small \
    --enable-gpl \
    --disable-doc \
    --disable-programs \
    --disable-avdevice \
    --enable-cross-compile \
    --target-os=android \
    --arch=$ARCH \
    --cc=$TOOLCHAIN/bin/$ARCH2-linux-android$API-clang \
    --cross-prefix=$TOOLCHAIN/bin/$ARCH2-linux-android-
	
    #清除上次编译
    make clean
    make -j40
    make install
}
#开始编译
build

一般上面脚本可以直接拷贝使用,只需要改如下两项和路径直接关联的

PREFIX=/home/test/ffmpeg_64/out/
#此处路径替换为当前NDK路径
TOOLCHAIN=/home/test/Downloads/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64

准备上面脚本拷贝到FFmpeg的源码路径进行执行:

~/demos/ffmpeg$ sudo sh build_64_1.sh

注意带上sudo 哈
执行成功后如果没有报啥错,既可以在设置的目录看到如下几个部分
在这里插入图片描述在这里插入图片描述

一般使用include和lib既可以

上面就是ndk编译ffmepg的64位库简单过程哈,同理32位库也是一样,只需要改动一点config参数既可以,具体也给出对应sh脚本

#!/bin/bash
API=21
#arm64  x86 x86_64 <----> aarch64  i686  x86_64
ARCH=arm
ARCH2=armv7a    
PREFIX=/home/test/ffmpeg_32/out/

TOOLCHAIN=/home/test/Downloads/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64

build()
{

    ./configure \
    --prefix=$PREFIX \
    --disable-static \
    --enable-shared \
    --enable-small \
    --enable-gpl \
    --disable-doc \
    --disable-programs \
    --disable-avdevice \
    --enable-cross-compile \
    --target-os=android \
    --arch=$ARCH \
    --cc=$TOOLCHAIN/bin/$ARCH2-linux-androideabi$API-clang \
    --cross-prefix=$TOOLCHAIN/bin/$ARCH-linux-androideabi-


    make clean
    make -j40
    make install
}

build

有了相关的so和include后,既可以把它们用于开发app啦

Android Studio上使用相关FFmpeg的so进行开发

建立一个简单的native c++的工程
在这里插入图片描述
然后进行同步编译通过,在进行导入FFmpeg相关的头文件和lib
在这里插入图片描述
这些库和include的头文件放好,然后开始编写对应的CMakeList进行相关的修改

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
#设置好ffmpeg_lib_dir这个变量的路径
set(ffmpeg_lib_dir ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${CMAKE_ANDROID_ARCH_ABI})
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             native-lib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )
#针对一个个的库进行挨个导入
add_library(avutil SHARED IMPORTED)
set_target_properties( avutil PROPERTIES IMPORTED_LOCATION  ${ffmpeg_lib_dir}/libavutil.so)

add_library(avcodec SHARED IMPORTED)
set_target_properties( avcodec PROPERTIES IMPORTED_LOCATION  ${ffmpeg_lib_dir}/libavcodec.so)

add_library(avformat SHARED IMPORTED)
set_target_properties( avformat PROPERTIES IMPORTED_LOCATION  ${ffmpeg_lib_dir}/libavformat.so)

add_library(swscale SHARED IMPORTED)
set_target_properties( swscale PROPERTIES IMPORTED_LOCATION  ${ffmpeg_lib_dir}/libswscale.so)

add_library(avfilter SHARED IMPORTED)
set_target_properties( avfilter PROPERTIES IMPORTED_LOCATION  ${ffmpeg_lib_dir}/libavfilter.so)

add_library(postproc SHARED IMPORTED)
set_target_properties( postproc PROPERTIES IMPORTED_LOCATION  ${ffmpeg_lib_dir}/libpostproc.so)

add_library(swresample SHARED IMPORTED)
set_target_properties( swresample PROPERTIES IMPORTED_LOCATION  ${ffmpeg_lib_dir}/libswresample.so)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       native-lib

                        avutil
                        avcodec
                        avformat
                        swscale
                        avfilter
                        postproc
                        swresample
                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

上面配置好了以后既可以进入下一步编写测试代码了,代码如下:
MainActivity.java

package com.example.myffmpeg;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    // Used to load the 'native-lib' library on application startup.
    static {
        System.loadLibrary("native-lib");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Example of a call to a native method
        TextView tv = findViewById(R.id.sample_text);
        tv.setText(getFFmpegConfig());
        TextView version = findViewById(R.id.version);
        version.setText(version());
    }

    /**
     * A native method that is implemented by the 'native-lib' native library,
     * which is packaged with this application.
     */
    public native String version();
    public native String getFFmpegConfig();

}

native-lib.cpp

#include <jni.h>
#include <string>

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>

JNIEXPORT jstring JNICALL Java_com_example_myffmpeg_MainActivity_version(
    JNIEnv* env,
    jobject /* this */) {
std::string hello = "Hello from C++";
//返回FFmpeg的版本
return env->NewStringUTF(av_version_info());
}
JNIEXPORT jstring JNICALL  Java_com_example_myffmpeg_MainActivity_getFFmpegConfig(
        JNIEnv* env,
jobject /* this */) {
//返回FFmpeg的相关配置,其实就是编译时候的
return env->NewStringUTF(avcodec_configuration());
}

}

最后运行如下:
在这里插入图片描述

更多framework干货请关注“千里马学框架”

Ubuntu系统-FFmpeg安装及环境配置 FCN-4是一个应用于音频自动标注的全卷积神经网络。使用该网络完成音频标注任务时,首先需要使用python的音频处理工具包Librosa提取音频的时频特征,针对mp3格式的音频文件,Librosa读取音频文件的工作依赖音频处理后端ffmpeg完成,因此要求使用该网络进行mp3音频自动标注任务的环境具备Librosa依赖库和ffmpeg。Librosa是一个用于音频、音乐分析、处理的python工具包,具备时频处理、特征提取、绘制声音图形等常用功能。 阅读详情

相关推荐

Ubuntu 16.04下交叉编译android Ffmpeg库,支持neon加速和硬解码。

环境 1.Ubuntu 16.04(windows上安装的虚拟机) 2.NDK版本,android-ndk-r14b 下载Ffmpeg源码 这里提供ffmpeg官网下载地址http://ffmpeg.org/download.html。可以直接下载压缩包解压或者直接用git下载,我目前下载的是ffmpeg3.4版本。 git下载命令为:git clone https://git.ffm...

u011866128的博客 1717

Ubuntu下FFmpeg的安装方式

Ubuntu下FFmpeg的安装方式详细版

日常记录,挨打要立正! 1万+

Android NDK(ndk-r16b)交叉编译FFmpeg(3.3.9)

超详细编译ffmpeg3.3.9生成so库

Jushuzhan的专栏 2887

ubuntu配置ffmpeg以及基本使用

ubuntu 基本使用

QG 4098

Ubuntu下编译Ffmpeg静态库

在开发一款android平台下的视频播放器,底层解码选择用开源解码库Ffmpeg,需要编译生成静态库。      编译的环境:      ubuntu 12.04 64bit      android-ndk-r9d linux 64bit,下载地址:android ndk下载地址      ffmpeg 0.6.7,下载地址:Ffmpeg 0.6.7 源码下载地址     编译的详

looong2b的专栏 4661

ffmpeg2.6.2在Ubuntu下使用NDK编译成.so文件

参考文章:http://www.cnblogs.com/wainiwann/p/3785485.html ------------------------------------------------------------------------- 1、 配置环境: 安装Ubuntu 10.04.4 2、下载ffmpeg-2.6.2.tar.bz2 3、下载android-ndk-

xm447975373的专栏 1239

3.1 Android NDK交叉编译FFmpeg

本文介绍了在Ubuntu 20.04环境下使用NDK编译多个FFmpeg版本(4.4.6、5.1.6、6.1.2、7.0.2)的完整流程。项目包含自动下载脚本(NDK、FFmpeg源码及依赖项x264/fdk-aac)和编译控制脚本,支持分架构(arm64-v8a/armeabi-v7a)输出。目录结构清晰,包含源码目录(deps/ffmpeg)、NDK工具链和编译输出目录(output)。使用build_android.sh脚本可一键编译全部组件或单独编译指定库,通过代理设置加速下载。编译结果按版本和架构

卖猪肉的痴汉 1534

Android NDK 入门指南:在 Ubuntu 上进行编程

通过结合使用 Java 和本地代码,开发者可以充分发挥本地语言的性能优势,从而提高 Android 应用的性能和功能。在 src/main 目录下创建一个名为 jni 的文件夹,并在该文件夹中创建一个名为 native-lib.cpp 的源文件。通过使用 Android NDK,你可以进一步探索使用 C、C++ 和其他本地语言开发高性能的 Android 应用程序的能力。以下是一个简单的示例,展示了如何编写一个使用本地代码的 Android 应用程序。首先,创建一个新的 Android 项目。

ByteGlide的博客 404

ffmpeg学习:ubuntu下编译Android版ffmpeg-kit

ubuntu下编译Android版的ffmpeg-kit

RQ997832的专栏 2493

Rider高效调试UE引擎:无需编译源码的符号配置指南

本文提供了一份详尽的Rider高效调试UE引擎指南,核心在于无需编译源码即可配置调试符号。通过Epic启动器下载官方PDB文件,并在Rider中正确配置外部符号服务器路径,开发者能在10分钟内实现对引擎内部代码(如AActor::Tick)的源码级断点调试、变量查看和调用堆栈分析,极大提升问题排查效率。

weixin_29011239的博客 343

VSCode关联VIVADO编辑Verilog

有时候接手别人的代码,或者从网上找的开源代码,每个人风格不一致,对齐缩进也不一样,阅读起来很累。有没有什么方法能快捷地格式化代码呢。下面我们利用VSCode插件来实现这个需求。Vivado是Xilinx公司提供的逻辑开发平台(之一),如果不喜欢Vivado自带的文本编辑器,可以选择第三方的文本编辑器VSCode。

小王在努力...的博客 7151

Ubuntu18.04下编译FFmpeg for Android

模仿、求学都不是我们的目的,最终我们都希望在求知的过程中,有所领悟。最终走出自己的道。淡定、从容,如果不是刻意伪装,相信当事者必有丰富的人生阅历。把学习记录下面,不仅是为了备忘,更是对学习过程的梳理。当我们可以站在过去的肩膀上,又可以很好地向别人表达自己的思想。相信我们的人生一定会更加精彩。道路维艰,且让我们脚踏实地,步步为营。 下面的文章参考了众多博客,亦夹杂了个人在编译过...

n_fly的博客 1265

CAD图纸智能搜索三大突破:图纸秒搜技术、相似度匹配与AI语义搜索

CAD图纸作为核心资产,长期面临管理难题:传统全文检索需逐张打开图纸人工查找,效率低下;相似图纸匹配依赖人工比对,误差率高;非专业人员难以通过模糊描述精准定位图纸。针对这些问题,唯杰地图推出三项智能解决方案:一是基于现代化索引引擎的​​全文搜索​​,支持秒级检索图纸内的文字、图层、块名称等,并可多条件组合查询;二是​​相似度搜索​​,通过SIFT算法和深度学习提取几何特征与拓扑结构,实现高精度匹配;三是​​AI语义搜索​​,利用大模型解析自然语言指令(如“查找半径为10的红色圆”),直接定位目标图形。

vjmap的博客 1871

Android FFMPEG编解码实践(一):Ubuntu 22.04 NDK编译FFMPEG+libx264

linux系统下使用ndk交叉编译ffmpeg+x264

selivert的博客 3460

告别手工AS91/AB01L:用BAPI_FIXEDASSET_OVRTAKE_CREATE实现SAP资产历史数据自动化迁移

本文详细解析了如何利用BAPI_FIXEDASSET_OVRTAKE_CREATE实现SAP资产历史数据的自动化迁移,替代传统手工操作如AS91/AB01L。通过核心参数解析、迁移逻辑说明及实战案例,帮助顾问团队提升资产和折旧数据迁移的效率与准确性,确保数据一致性并降低错误风险。

weixin_42524708的博客 420

电脑技巧:Hyper-V安装UOS操作系统图文教程

今天给大家分享微软官方Hyper-v虚拟机管理软件安装UOS操作系统图文教程,感兴趣的朋友也可以下载试一试,当然有啥问题也可以互相沟通交流!

IT技术分享社区 4707

编译好ffmpeg so文件用于安卓:高效部署视频处理功能

编译好ffmpeg so文件用于安卓:高效部署视频处理功能 去发现同类优质开源项目:https://gitcode.com/ 项目介绍 在移动应用开发中,视频处理与播放功能是许多应用的核心需求。今天,我们将为您介绍一个能够大幅简化开发流程的开源项目——编译好ffmpeg so文件用于安卓。该项目提供了一种在Ubuntu 16.04系统下编译的ffmpeg 2020版本so文件,专门针对QT 5.1...

gitblog_06743的博客 845

5、癌症数据预处理技术与深度学习在癌症预测中的应用

本文详细介绍了癌症数据预处理技术和深度学习在癌症预测中的应用。针对CT扫描图像、X射线图像、超声图像、基因表达数据和文本数据等不同类型的癌症数据,分别阐述了去噪、插值、配准、归一化等预处理技术的具体方法。同时,分析了深度学习在乳腺癌、白血病和宫颈癌预测中的作用,结合相关影响因素探讨了模型的应用潜力。此外,还总结了深度学习在癌症预测中面临的挑战及未来发展方向,为癌症的早期诊断与精准预测提供了理论支持和技术参考。

alice7model的博客 123

NDK编译FFMPEG5.0

编译环境 系统:ubuntu 20.04.4 ffmpge 5.0 下载地址: https://ffmpeg.org/download.html android-ndk-r23b-linux 下载地址: https://developer.android.google.cn/ndk/downloads?hl=zh-cn (选择linux版本) 解压文件 创建脚本 touch build_android.sh #!/bin/bash # 以下路径需要修改成自己的NDK目录 TOO

那个谁的博客 3739

〖Python网络爬虫实战㊴〗- 极验滑块介绍(一)

我们对这个看到不陌生,现在,大多数平台都是用的是这个平台的验证码,我们今天来学习一下,极验滑块验证码的逆向,其他的都差不多。我们了解到这个平台提供了许多验证的方式。现在大多数还是滑块比较多,滑块验证码是一种常见的验证方式,其主要思路为用户通过拖动滑块来完成验证。具体流程如下:首先,用户需要进行滑块验证码的操作,网站会向用户展示一张图片,图片上通常会有一些随机的文字和背景干扰。用户需要通过鼠标拖动滑块,将其移动到指定位置上,通常是将滑块拖动到图片的相应位置上来完成验证。

爱吃饼干的小白鼠的博客 2879

simulink的电动汽车制动系统热管理仿真

本文系统研究了电动汽车制动系统热管理仿真技术。通过建立机电液多物理场耦合模型,分析了不同工况下的动态热平衡特性。提出基于MPC的动态调节和NSGA-II多目标优化算法,使电池温度波动降低60%。创新性采用石墨烯相变材料与微通道液冷复合技术,冷却系统能耗减少40%。研究构建了完整的工程验证平台,涵盖200kW电制动测试台和高精度热成像系统。展望指出,未来将结合Transformer预测和强化学习算法,进一步优化热管理策略。该研究为电动汽车制动系统热管理提供了从理论建模到工程实施的完整解决方案。

xiaoheshang_123的博客 122

用android ndk编译ffmpeg,[Android开发]使用NDK编译FFmpeg到Android下使用

这次使用 ndk r14 进行对 ffmpeg 3.2.4编译,使其能移植到Android下使用之前尝试在window 10环境下用NDK对FFmpeg进行编译,发现坑太多,各种路径不认。最后还是决定在虚拟机上安装Ubuntu再对其编译。前期准备:1.安装好虚拟机,这里之前安装的是VirtualBox 5.0.26的版本2.在虚拟机上安装Ubuntu,这里采用的是ubuntu 14.04 LTS...

weixin_28933797的博客 455

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

FFmpeg编译Android版本

FFmpeg是很好用的一个音视频库,功能强大,但是用起来并不是很方便。之前一直不想用FFmpeg,因为感觉编译太麻烦,但是到了不得不用的时候了,没办法,参考了网上大神的方法,在这里自己也记录一下方便以后再次查看。 一、环境         Ubuntu14.04 二、NDK环境配置         NDK下载链接:https://developer.android.goog

红嘴唇小丑的博客 1759

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

ffmpeg(一) android ndk编译ffmpeg

android 使用ffmpeg,用Android ndk编译ffmpeg

pangrui201的专栏 1008

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Android FFmpeg5.0 ubuntu 编译

一、FFmpeg 库编译。 1.环境 win10 子系统 Ubuntu 20.04.1 LTS ndk R22 FFmpeg 5.0 下载后直接解压。 2.问题解决和改动 1.执行./configure,报出了如下错误 nasm/yasm not found or too old. Use –disable-x86asm for a crippled build. ./configure --disable-x86asm 2.脚本 android_build.sh 直接在win系统内创建的

m0_60259116的博客 1075
上一篇: Vsync之app层面深入分析
下一篇: systemserver为啥很少同步跨进程调用app/DeadSystemException相关问题分析套路
千里马学框架
博客等级 码龄6年 1万+粉丝 651原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

千里马学框架

帮助你了,就请我喝杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值