AVFoundation编程指南

如何在iPhone视频中实现空间音频:编程指南 在iPhone上启用空间音频是一种增强用户体验的方式,它可以为观看视频时提供更加沉浸的音频效果。本文将为您提供一个详细的编程指南,教您如何在iPhone视频上启用空间音频。在Xcode的导航面板中,找到项目文件夹并展开它。这就是在iPhone视频中启用空间音频的编程指南。通过遵循上述步骤,您可以为您的iOS应用程序添加更加沉浸的音频效果。在项目中创建一个UIViewController子类,并在该类中实现视频播放器的逻辑。当您打开视频播放器界面时,您应该能够享受到启用了空间音频的视频体验。 阅读详情

AVFoundation编程指南1-使用资产

原文链接:http://1199game.com/2016/10/avfoundation-1/

创建断言对象

为了创建一个由URL标识的代表任何资源的断言对象,可以使用AVURLAssert,最简单的是从文件里创建一个断言对象:

NSURL *url = <#A URL that identifies an audiovisual asset such as a movie file#>;
AVURLAsset *anAsset = [[AVURLAsset alloc] initWithURL:url options:nil];

资产初始化的可选操作

AVURLAsset初始化方法的第二个参数使用一个字典,这个字典里的唯一一个关键是AVURLAssetPreferPreciseDurationAndTimingKey,它的值是一个布尔类型(用NSValue包装的对象),这个值表示资产是否提供一个精确的持续时间获取资产精确的持续时间需要很多处理时间,使用一个预估的持续时间效率比较高并且对播放来说足够。因此:·如果你想要播放资产,初始化方法传nil就行了,而不是一个字典,或者传一个以AVURLAssetPreferPreciseDurationAndTimingKeydictionary为key,值为NO的一个字典·如果你想把资产加到一个组成中,你需要一个精确的访问权限,这时你可以传一个字典,这个字典的一组键值对为

AVURLAssetPreferPreciseDurationAndTimingKey和YES。
NSURL *url = <#A URL that identifies an audiovisual asset such as a movie file#>;
NSDictionary *options = @{ AVURLAssetPreferPreciseDurationAndTimingKey : @YES };
AVURLAsset *anAssetToUseInAComposition = [[AVURLAsset alloc] initWithURL:url options:options];

访问用户的资产

为了访问iPod库和相册里资产,你需要获取资产的URL。·为了访问ipod库,需要创建MPMediaQuery对象来找到你想要对象,然后通过MPMediaItemPropertyAssetURL获取它的URL要求获取更多关于媒体库,查看多媒体编程指南。·为了访问相册,可以使用ALAssetsLibrary。下面的例子用来获取相册里面的第一个视频:ALAssetsLibrary * library = [[ALAssetsLibrary alloc] init];

// Enumerate just the photos and videos group by using ALAssetsGroupSavedPhotos.
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
usingBlock:^(ALAssetsGroup *group, BOOL *stop) {

// Within the group enumeration block, filter to enumerate just videos.
[group setAssetsFilter:[ALAssetsFilter allVideos]];

// For this example, we're only interested in the first item.
[group enumerateAssetsAtIndexes:[NSIndexSet indexSetWithIndex:0]
options:0
usingBlock:^(ALAsset *alAsset, NSUInteger index, BOOL *innerStop) {

// The end of the enumeration is signaled by asset == nil.
if (alAsset) {
ALAssetRepresentation *representation = [alAsset defaultRepresentation];
NSURL *url = [representation url];
AVAsset *avAsset = [AVURLAsset URLAssetWithURL:url options:nil];
// Do something interesting with the AV asset.
}
}];
}
failureBlock: ^(NSError *error) {
// Typically you should handle an error more gracefully than this.
NSLog(@"No groups");
}];

准备使用资产

初始化一个资产(或者曲目)并不是表示资产里面所有的信息都是马上可用的。它需要一些时间去计算,即使是durtation(比如没有摘要信息的MP3文件),你应该使用AVAsynchronousKeyValueLoading协议获取这些值,通过 - loadValuesAsynchronouslyForKeys:completionHandler:在处理程序里面获取你要的值你可以用statusOfValueForKey:error:测试一个属性的值是否成功获取,当一个assert第一次被加载,大多数属性的值是AVKeyValueStatusUnknown状态,为了获取一个或多个属性的值,你要调用loadValuesAsynchronouslyForKeys:completionHandler :,在comletiton处理程序里面,你可以根据属性的状态做任何合适的处理你要处理加载没有成功的情况,可能因为一些原因比如网络不可连接,又或者装载被取消。

NSURL *url = <#A URL that identifies an audiovisual asset such as a movie file#>;
AVURLAsset *anAsset = [[AVURLAsset alloc] initWithURL:url options:nil];
NSArray *keys = @[@"duration"];

[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^() {

NSError *error = nil;
AVKeyValueStatus tracksStatus = [asset statusOfValueForKey:@"duration" error:&error];
switch (tracksStatus) {
case AVKeyValueStatusLoaded:
[self updateUserInterfaceForDuration];
break;
case AVKeyValueStatusFailed:
[self reportError:error forAsset:asset];
break;
case AVKeyValueStatusCancelled:
// Do whatever is appropriate for cancelation.
break;
}
}];

如果你想要播放的资产,你应该加载他的轨道属性。

从视频中获取静态图片

从资产中获取静态图片(比如说缩略图),你可以用AVAssetImageGenerator对象。可以用资产初始化一个AVAssetImageGenerator对象。即使资产在初始化的时候没有可见的轨道也能成功,所以你应该检测资产是否有轨道,使用tracksWithMediaCharacteristic:

AVAsset anAsset = <#Get an asset#>;
if ([[anAsset tracksWithMediaType:AVMediaTypeVideo] count] > 0) {
AVAssetImageGenerator *imageGenerator =
[AVAssetImageGenerator assetImageGeneratorWithAsset:anAsset];
// Implementation continues...
}

你还可以设置imagegenerator的其他属性,比如,你可以指定生成图片的最大的分辨率,你可以生成指定时间的一张片,或者一系列图片。你必须一直持有发生器的引用,直到生成所有的图片。

生成单个图片

你可以使用copyCGImageAtTime:actualTime:错误:生成一张指定时间点的图片.AVFoundation不一定能精确的生成一张你所指定时间的图片,所以你可以在第二个参数传一个CMTime的指针,用来获取所生成图片的精确时间。

AVAsset *myAsset = <#An asset#>];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:myAsset];

Float64 durationSeconds = CMTimeGetSeconds([myAsset duration]);
CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600);
NSError *error;
CMTime actualTime;

CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error];

if (halfWayImage != NULL) {

NSString *actualTimeString = (NSString *)CMTimeCopyDescription(NULL, actualTime);
NSString *requestedTimeString = (NSString *)CMTimeCopyDescription(NULL, midpoint);
NSLog(@"Got halfWayImage: Asked for %@, got %@", requestedTimeString, actualTimeString);

// Do something interesting with the image.
CGImageRelease(halfWayImage);
}

生成一系列图片

为了生成一系列图片,你可以调用generateCGImagesAsynchronouslyForTimes:completionHandler:,第一个参数是一个包含NSValue类型的数组,数组里每一个对象都是CMTime结构体,表示你想要生成的图片在视频中的时间点,第二个参数是一个块,每生成一张图片都会回调这个块,这个块提供一个结果的参数告诉你图片是否成功生成或者图片生成操作是否取消。

在你的块实现中,需要检查结果,判断图像是否成功生成,另外,确保你持有图像生成器直到生成图片的操作结束。

AVAsset *myAsset = <#An asset#>];
// Assume: @property (strong) AVAssetImageGenerator *imageGenerator;
self.imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:myAsset];

Float64 durationSeconds = CMTimeGetSeconds([myAsset duration]);
CMTime firstThird = CMTimeMakeWithSeconds(durationSeconds/3.0, 600);
CMTime secondThird = CMTimeMakeWithSeconds(durationSeconds*2.0/3.0, 600);
CMTime end = CMTimeMakeWithSeconds(durationSeconds, 600);
NSArray *times = @[NSValue valueWithCMTime:kCMTimeZero],
[NSValue valueWithCMTime:firstThird], [NSValue valueWithCMTime:secondThird],
[NSValue valueWithCMTime:end]];

[imageGenerator generateCGImagesAsynchronouslyForTimes:times
completionHandler:^(CMTime requestedTime, CGImageRef image, CMTime actualTime,
AVAssetImageGeneratorResult result, NSError *error) {

NSString *requestedTimeString = (NSString *)
CFBridgingRelease(CMTimeCopyDescription(NULL, requestedTime));
NSString *actualTimeString = (NSString *)
CFBridgingRelease(CMTimeCopyDescription(NULL, actualTime));
NSLog(@"Requested: %@; actual %@", requestedTimeString, actualTimeString);

if (result == AVAssetImageGeneratorSucceeded) {
// Do something interesting with the image.
}

if (result == AVAssetImageGeneratorFailed) {
NSLog(@"Failed with error: %@", [error localizedDescription]);
}
if (result == AVAssetImageGeneratorCancelled) {
NSLog(@"Canceled");
}
}];

你也可以取消生成图片的操作,通过想发生器发送cancelAllCGImageGeneration的消息

裁剪视频和对视频转码

你可以对视频进行转码,裁剪,通过使用AVAssetExportSession对象。这个流程如下图所示,

一个出口会话是一个控制对象,可以异步的生成一个资产。可以用你需要生成的资产和预设名称来初始化一个会话,presetName指明你要生成的资产的属性。接下来你可以配置出口会议,比如可以指定输出的URL和文件类型,以及其他的设置,比如metadata等等。你可以先检测设置的预设是否可用,通过使用exportPresetsCompatibleWithAsset:方法。

AVAsset *anAsset = <#Get an asset#>;
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetLowQuality]) {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc]
initWithAsset:anAsset presetName:AVAssetExportPresetLowQuality];
// Implementation continues.
}

你可以配置会话的输出的URL(这个URL必须是文件的URL),AVAssetExportSession可以推断通过URL的扩展名出输出文件的类型。当然,你可以直接设置文件类型,使用outputFileType。你还可以指定其他属性,比如时间范围,输出文件的长度等等,下面是列子:

exportSession.outputURL = <#A file URL#>;
exportSession.outputFileType = AVFileTypeQuickTimeMovie;

CMTime start = CMTimeMakeWithSeconds(1.0, 600);
CMTime duration = CMTimeMakeWithSeconds(3.0, 600);
CMTimeRange range = CMTimeRangeMake(start, duration);
exportSession.timeRange = range;

生成一个新的资产,可以调用exportAsynchronouslyWithCompletionHandler:,当生成操作结束后会回调块,在这个区块中你需要通过检查会话的状态来判断是否成功,如下

[exportSession exportAsynchronouslyWithCompletionHandler:^{

switch ([exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(@"Export canceled");
break;
default:
break;
}
}];

你可以取消这个生成操作,通过给会话发送cancelExport消息。如果导出的文件存在,或者导出的url在沙盒之外,这个导出操作会失败。还有两种情况也可能导致失败:·来了一个电话·你的程序在后台运行并且其他的应用开始播放。这种情况下,你应该通知用户出口失败,并且重新出口。

STM32L452与FPGA通信翻车?手把手教你关闭I2C时钟延展避坑(附OVR错误解决方案) 本文深入解析STM32L452与FPGA在I2C通信中因时钟延展功能导致的常见问题,提供关闭I2C时钟延展的详细配置方法(NOSTRETCH模式),并针对可能出现的OVR错误给出Combined模式解决方案。通过实战案例和波形分析,帮助工程师快速排查和解决嵌入式系统中的I2C兼容性问题。 阅读详情

相关推荐

M2DGR数据集在主流SLAM框架中的实战配置指南:从ORB-SLAM到FAST-LIO的完整流程

本文提供了M2DGR多传感器数据集在主流SLAM框架中的实战配置指南。详细介绍了从ORB-SLAM、VINS-Mono等视觉/视觉惯性框架,到A-LOAM、FAST-LIO等激光/激光惯性框架的完整配置流程、参数调整要点及常见问题解决方案。通过实际测试对比,分析了各算法在M2DGR数据集上的表现,为机器人定位与建图研究提供了宝贵的实战经验。

k9l0m1的博客 481

AVAssetExportSession的exportAsynchronouslyWithCompletionHandler:回调不执行的原因

最近搞视频合并,遇到一个问题,测试手机与自己的手机都可以成功合并,但有一台测试iPod就失败,查原因,原来是合并时回调不执行,看苹果文档,明明失败与成功都会执行回调的。百思不得解,后来慢慢细看代码,发现原因:原视频是AVFileTypeMPEG4格式的,合并输出是设置的是AVFileTypeQuickTimeMovie, 试这把AVFileTypeQuickTimeMovie改为AVFileType

Care iOS技术团队 7217

深信服技术认证“SCCA-C”划重点:信服云托管云

该认证包括云数据中心基础、云计算基础、云计算关键技术、云计算交付和运维体系、云计算技术商业应用、信服云托管云、深信服超融合HCI、深信服桌面云aDesk、深信服分布式存储EDS、深信服应用交付AD。学习并获得SCCA-C认证后,可以具备深信服产品功能原理与实践,能够根据业务需求,协助完成云产品方案落地与实施;能够根据业务需求,完成深信服云产品的部署和管理的基本工作。为帮助大家更加系统化地学习云计算知识,高效通过云计算工程师认证,深信服特推出“SCCA-C认证备考秘笈”,共十期内容。

sangfor_edu的博客 613

视频拼接exportAsynchronouslyWithCompletionHandler block不调用问题

最近在做视频录制的项目,发现exportAsynchronouslyWithCompletionHandler block有时候不调用。 查了一下原因,在于文件类型设置,改为AVFileTypeQuickTimeMovie就可以了。 //[exportSession setOutputFileType:AVFileTypeMPEG4];  [exportSessi

jueyi1127的博客 4283

⭐️白嫖的阿里云认证⭐️ 【真题&参考答案】:大模型Clouder认证:利用大模型提升内容生产能力

【摘要】真题「大模型Clouder认证:利用大模型提升内容生产能力」

davidkorhenn的博客 1921

Kubernetes+EdgeX:构建企业级AI边缘推理平台

设备:工业摄像头(RTSP协议,输出1920x1080视频流);AI模型:YOLOv8训练的轴承裂纹检测模型(识别“裂纹”“正常”两种类型);目标:摄像头采集图像→EdgeX传输数据→K8s推理服务检测→结果反馈到报警器(HTTP协议)。Kubernetes+EdgeX的组合,为企业构建AI边缘推理平台提供了标准化、可扩展标准化:K8s的容器编排和EdgeX的设备管理,都是行业标准,避免“重复造轮子”;可扩展:支持从单边缘节点到 thousands of nodes 的规模,满足企业的增长需求;

AI算力网络与通信的博客 1344

AVAssetExportSession的问题

最近在搞视频的拼接碰到奇葩的问题:使用exportAsynchronouslyWithCompletionHandler怎么都不调用block,搞了2天的时间终于tmd的解决了,但是还是不知道什么原因,啃爹啊!      先说说怎么出这个问题的吧。自己录制了一些视频文件,这个文件的产生是通过AVAssetWriter输出的,并没有使用 AVCaptureFileOutputRecordingD

Tommy(凌飞)的专栏 1万+

36、基于启发式的双向RRT*路径规划算法解析

本文介绍了一种基于启发式的双向RRT*路径规划算法(LGHB-RRT*),通过地图预处理、通道区域提取和通道识别点定义,结合随机树的引导生长与可变密度采样机制,显著提升了在复杂通道环境下的搜索效率与成功率。算法采用双向扩展结构,并引入启发式生长策略引导树向通道关键点发展,同时利用路径优化简化最终路径。仿真结果表明,该算法在多种复杂地图中均能高效找到最优路径,优于传统RRT*和Bi-RRT*算法,具备良好的适应性与应用前景。

rgv234567的博客 116

AVAssetExportSession progress KVO

在使用AVAssetExportSession的 exportAsynchronouslyWithCompletionHandler接口时有个progress属性,打算用KVO去实现监听  static void *ExportProcess = &ExportProcess; [_exporter addObserver:self forKeyPath:@"progress" opti

jeffasd的专栏 2791

论文复现《基于最大李雅普诺夫指数的电力系统暂态电压稳定评估方案》

电力系统暂态电压稳定评估方案 摘要 本研究提出了一种基于最大李雅普诺夫指数的电力系统暂态电压稳定评估方法。通过分析相空间中相邻轨迹的收敛或发散特性,该方法能够提前判别系统稳定性。论文首先阐述了暂态电压稳定机理,详细介绍了最大李雅普诺夫指数的计算方法。针对IEEE-39节点系统,建立了仿真模型并获取不同故障场景下的数据。研究开发了完整的评估程序,包括数据预处理、相空间重构、指数计算等模块,并通过与时域仿真结果的对比验证了方法的准确性。实验结果表明,该方法能够快速有效地评估电力系统的暂态电压稳定性,为系统安全运

max500600的博客 187

TypeError: XGBClassifier.fit() got an unexpected keyword argument ‘early_stopping_rounds‘ 解决方案

本文主要介绍了TypeError: XGBClassifier.fit() got an unexpected keyword argument 'early_stopping_rounds’解决方案,希望能对使用XGBoost的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 1万+

AVFoundation 框架初探究(三)

这篇总结什么? 在该系列的上一篇的文章中,我们总结的大致内容如下: 1、视频录制 AVCaptureSession +AVCaptureMovieFileOutput 2、视频录制AVCaptureSession +AVAssetWriter 3、AVCaptureSession +AVCaptureMovie...

weixin_30617695的博客 224

【打卡帖】7日玩转ESP32——(第4日) 串口的输入输出

【福利帖】7日玩转ESP32——(第4日) 串口的输入输出

1376

AVFoundation编程指南02-概述

https://www.jianshu.com/p/09e3bd52a58e AVFoundation编程指南02-概述 0.1922019.05.13 16:14:10字数 2410阅读 126 写在前面 喜欢AVFoundation资料的同学可以关注我的专题:《AVFoundation》专辑 也可以关注我的简书账号 正文 AVFoundation是iOS开发者可以用来播放和创...

u010029439的博客 1469

深度学习工具包 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")

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

AVFoundation编程指南-使用 Assets

转载自:AVFoundation编程指南1-使用 AssetsAVFoundation Programming Guide创建assert对象为了创建一个由URL标识的代表任何资源的assert对象,可以使用AVURLAssert,最简单的是从文件里创建一个assert对象:NSURL *url = <#A URL that identifies an audiovisual asset such

了凡 679

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

AVFoundation 编程指南 mark to memorize

添加水印 //1 创建AVAsset实例 AVAsset包含了video的所有信息 self.videoUrl输入视频的路径 self.videoAsset = [AVAsset assetWithURL:self.videoUrl]; //2 创建AVMutableComposition实例. apple developer 里边的解释 【AVMutableComposit

kaka 1066

AVFoundation编程指南1-使用 Assets

https://segmentfault.com/a/1190000004049416?_ea=471318 AVFoundation Programming Guide 创建assert对象 为了创建一个由URL标识的代表任何资源的assert对象,可以使用AVURLAssert,最简单的是从文件里创建一个assert对象: NSURL *url = #A URL t

jeffasd的专栏 857

AVFoundation编程指南2-用AVPlayer播放视频

https://segmentfault.com/a/1190000004054258?_ea=474224 控制assets的播放,你可以使用AVPlayer对象。在播放的过程中,你可以使用AVPlayerItem对象来管理asset的呈现,AVPlayerItemTrack来管理track。要显示视频,需要使用AVPlayerLayer。 播放Assets 一个播放器

jeffasd的专栏 1414

AVFoundation编程指南文档-整理思维导图

官方文档地址 总结思维导图。

学习笔记 648

AVFoundation Programming Guide(官方文档翻译1)About AVFoundation - AVFoundation概述

AVFoundation 是可以用它来播放和创建基于时间的视听媒体的几个框架之一。它提供了基于时间的视听数据的详细级别上的Objective-C接口。例如,你可以用它来检查,创建,编辑或重新编码媒体文件。您也可以从设备得到输入流和在实时捕捉回放过程中操控视频。图I-1显示了iOS上的架构。

yofer张耀琦的专栏 6803

AVFoundation Programming Guide

AVFoundation Programming Guide https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/00_Introduction.html#//apple_ref/doc/uid/TP40010188-CH1-SW3

mandagod的博客 362

AVFoundation(一)

AVFoundation是可用于播放和创建基于时间的视听媒体的几种框架之一。它提供了一个Objective-C接口,您可以使用该接口详细处理基于时间的视听数据。例如,您可以使用它来检查、创建、编辑或重新编码媒体文件。您还可以从设备中获取输入流,并在实时捕获和回放期间操纵视频。图I-1显示了iOS上的体系结构。 通常,您应该使用可用的最高级别抽象来执行您想要的任务。 如果您只是想播放电影,请使用AVKit框架。 在iOS上,要在只需要对格式进行最小控制的情况下录制视频,请使用UIKit框架(UIImageP

Yuan 661

iOS Programming 101: Record and Play Audio using AVFoundation Framework

Editor’s note: Some of you asked us to write a tutorial about audio recording. This week, we work with Yiqi Shi and Raymond from Purple Development to give you an introduction of AVFoundation framew

brandon2015的博客 4125
上一篇: 过渡动画
下一篇: 谈谈 MVX 中的 Model
Philm_iOS
博客等级 码龄8年 74粉丝 53原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值