百度信息流平台郑州seo公司

pingmian/2025/10/8 11:52:31/文章来源:
百度信息流平台,郑州seo公司,好网站具备条件,理解电子商务网站建设与管理目录 前言总体设计系统整体结构图系统流程图 运行环境模块实现1. 数据预处理2. 模型构建3. 模型训练及保存1#xff09;模型训练2#xff09;模型保存 4. 模型生成1#xff09;模型导入及调用2#xff09;相关代码#xff08;1#xff09;布局文件#xff08;2#xff… 目录 前言总体设计系统整体结构图系统流程图 运行环境模块实现1. 数据预处理2. 模型构建3. 模型训练及保存1模型训练2模型保存 4. 模型生成1模型导入及调用2相关代码1布局文件2主活动类 相关其它博客工程源代码下载其它资料下载 前言 本项目采用VGG-16网络模型使用Kaggle开源数据集旨在提取图片中的用户特征最终在移动端实现对不良驾驶行为的识别功能。 首先通过使用VGG-16网络模型本项目能够深入学习和理解驾驶场景图像中的特征。VGG-16是一种深度卷积神经网络特别适用于图像识别任务通过多层次的卷积和池化层能够有效地提取图像中的抽象特征。 其次项目利用Kaggle提供的开源数据集包括各种驾驶场景图像覆盖了不同的驾驶行为和条件。这样的数据集是训练模型所需的关键资源。 接下来利用训练好的VGG-16模型项目提取图像中的用户特征。包括驾驶行为的姿势、眼神、手部动作等方面的特征有助于判断是否存在不良驾驶行为。 最后通过在移动端实现这个模型可以将不良驾驶行为的识别功能直接部署到车辆或驾驶辅助系统中。这种实时的、移动端的识别方案有望在驾驶安全和监管方面发挥积极的作用。 总的来说项目结合了深度学习、图像处理和移动端技术致力于实现对不良驾驶行为的智能化识别为提升驾驶安全提供了一种创新的解决方案。 总体设计 本部分包括系统整体结构图和系统流程图。 系统整体结构图 系统整体结构如图所示。 系统流程图 系统流程如图所示。 VGG-16网络架构如图所示。 运行环境 本部分包括Python环境、TensorFlow环境、Pycharm环境和Android环境。 详见博客。 模块实现 本项目包括4个模块数据预处理、模型构建、模型训练及保存、模型生成。下面分别给出各模块的功能介绍及相关代码。 1. 数据预处理 本部分包括数据集来源、内容和预处理。 详见博客。 2. 模型构建 数据加载进模型之后需要定义模型结构并优化损失函数。 详见博客。 3. 模型训练及保存 在定义模型架构和编译后通过训练集训练使模型可以识别数据集中图像的特征。 1模型训练 模型训练相关代码如下 train_generator train_datagen.flow_from_directory(train_data_dir, target_size(img_height, img_width), batch_size32, class_modecategorical) #读取训练集 validation_generator train_datagen.flow_from_directory(validation_data_dir, target_size(img_height, img_width), batch_size32, class_modecategorical) #读取验证集 model.fit_generator(train_generator, samples_per_epochnb_train_samples, epochsnb_epoch, validation_datavalidation_generator, nb_val_samplesnb_validation_samples) #训练模型 model.save(modelweights.h5) #保存模型及权重2模型保存 上述由Keras库生成的模型及权重文件为.h5格式为了能够被Android程序读取需要将.h5文件转换为.pb格式的文件模型被保存后可以被重用也可以移植到其他环境中使用。 def h5_to_pb(h5_model, output_dir, model_name, out_prefixoutput_, log_tensorboardTrue):#.h5模型文件转换成.pb模型文件if os.path.exists(output_dir) False:os.mkdir(output_dir)out_nodes []for i in range(len(h5_model.outputs)):out_nodes.append(out_prefix str(i 1))tf.identity(h5_model.output[i], out_prefix str(i 1))sess backend.get_session()from tensorflow.python.framework import graph_util, graph_io#写入.pb模型文件init_graph sess.graph.as_graph_def()main_graph graph_util.convert_variables_to_constants(sess, init_graph, out_nodes)graph_io.write_graph(main_graph, output_dir, namemodel_name, as_textFalse)#输出日志文件if log_tensorboard:from tensorflow.python.tools import import_pb_to_tensorboardimport_pb_to_tensorboard.import_to_tensorboard(os.path.join(output_dir, model_name), output_dir)4. 模型生成 将图片转化为数据输入TensorFlow的模型中并获取输出。 1模型导入及调用 本部分包括模型导入及调用的操作方法。 a. 编写代码进行实际预测之前,需要将转换后的模型添加到应用程序的资源文件夹中。在Android Studio中,鼠标右键项目,跳转至Add Folder(添加文件夹)部分,并选择AssetsFolder(资源文件夹)。在应用程序目录中创建一个资源文件夹,将模型复制到其中,如图所示。 b. 将新的Java类添加到项目的主程序包中并命名为ImageUtilsImageUtils为图片工具类,可用于Bitmap、byte、array、Drawable图片类型之间进行转换以及缩放。 相关代码如下 package com.example.doremi.testkeras2tensorflow; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Matrix; import android.os.Environment; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import org.json.*; //用于处理图像的实用程序类 public class ImageUtils {/**返回转换矩阵,处理裁切如果需要保持宽高比和旋转*参数srcWidth为源帧的宽度*参数srcHeight为源帧的高度*参数dstWidth为目标帧的宽度*参数dstHeight为目标帧的高度*参数applyRotation为旋转的角度为90°的整数倍*参数maintainAspectRatio为是否维持缩放比例*返回满足所需要求的转换*/public static Matrix getTransformationMatrix(final int srcWidth,final int srcHeight,final int dstWidth,final int dstHeight,final int applyRotation,final boolean maintainAspectRatio) {final Matrix matrix new Matrix();if (applyRotation ! 0) {//进行平移使图像中心在原点matrix.postTranslate(-srcWidth / 2.0f, -srcHeight / 2.0f);//绕原点旋转matrix.postRotate(applyRotation);}//考虑已经应用的旋转如果有然后确定每个轴需要多少缩放。final boolean transpose (Math.abs(applyRotation) 90) % 180 0;final int inWidth transpose ? srcHeight : srcWidth;final int inHeight transpose ? srcWidth : srcHeight;//必要时应用缩放if (inWidth ! dstWidth || inHeight ! dstHeight) {final float scaleFactorX dstWidth / (float) inWidth;final float scaleFactorY dstHeight / (float) inHeight;if (maintainAspectRatio) {//按最小比例缩放以便在保持宽高比的同时完全填充某些图像可能会截掉边缘final float scaleFactor Math.max(scaleFactorX, scaleFactorY);matrix.postScale(scaleFactor, scaleFactor);} else {//精确缩放matrix.postScale(scaleFactorX, scaleFactorY);}}if (applyRotation ! 0) {//从以原点为中心的参考转换回目标帧matrix.postTranslate(dstWidth / 2.0f, dstHeight / 2.0f);}return matrix;}public static Bitmap processBitmap(Bitmap source,int size){int image_height source.getHeight();int image_width source.getWidth();Bitmap croppedBitmap Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);Matrix frameToCropTransformations getTransformationMatrix(image_width,image_height,size,size,0,false);Matrix cropToFrameTransformations new Matrix();frameToCropTransformations.invert(cropToFrameTransformations);final Canvas canvas new Canvas(croppedBitmap);canvas.drawBitmap(source, frameToCropTransformations, null);return croppedBitmap;}public static float[] normalizeBitmap(Bitmap source,int size,float mean,float std){float[] output new float[size * size * 3];int[] intValues new int[source.getHeight() * source.getWidth()];source.getPixels(intValues, 0, source.getWidth(), 0, 0, source.getWidth(), source.getHeight());for (int i 0; i intValues.length; i) {final int val intValues[i];output[i * 3] (((val 16) 0xFF) - mean)/std;output[i * 3 1] (((val 8) 0xFF) - mean)/std;output[i * 3 2] ((val 0xFF) - mean)/std;}return output;}public static Object[] argmax(float[] array){int best -1;float best_confidence 0.0f;for(int i 0;i array.length;i){float value array[i];if (value best_confidence){best_confidence value;best i;}}return new Object[]{best,best_confidence};}public static String getLabel( InputStream jsonStream,int index){String label ;try {byte[] jsonData new byte[jsonStream.available()];jsonStream.read(jsonData);jsonStream.close();String jsonString new String(jsonData,utf-8);JSONObject object new JSONObject(jsonString);label object.getString(String.valueOf(index));}catch (Exception e){}return label;} }c. 在主活动main activity添加代码被用于显示图像和预测结果。 public void predict(final Bitmap bitmap){//在后台线程中运行预测new AsyncTaskInteger,Integer,Integer(){Overrideprotected Integer doInBackground(Integer ...params){//将图像大小调整为150*150Bitmap resized_image ImageUtils.processBitmap(bitmap,150);//归一化像素floatValuesImageUtils.normalizeBitmap(resized_image,150,127.5f,1.0f);//将输入传到tensorflowtf.feed(INPUT_NAME,floatValues,1,150,150,3);//计算预测tf.run(new String[]{OUTPUT_NAME});//将输出复制到预测数组中tf.fetch(OUTPUT_NAME,PREDICTIONS);//获得最高预测Object[] results argmax(PREDICTIONS);int class_index (Integer) results[0];float confidence (Float) results[1];try{final String conf String.valueOf(confidence * 100).substring(0,5);//将预测的类别索引转换为实际的标签名称final String label ImageUtils.getLabel(getAssets().open(labels.json),class_index);//展示结果runOnUiThread(new Runnable() {Overridepublic void run() {progressBar.dismiss();resultView.setText(label : conf %);}});}catch (Exception e){}return 0;}}.execute(0); }2相关代码 本部分包括布局文件和主活动类。 1布局文件 布局文件相关代码如下 /res/layout/activity_main.xml ?xml version1.0 encodingutf-8? android.support.design.widget.CoordinatorLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parenttools:context.MainActivityandroid.support.design.widget.AppBarLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:themestyle/AppTheme.AppBarOverlayandroid.support.v7.widget.Toolbarandroid:idid/toolbarandroid:layout_widthmatch_parentandroid:layout_height?attr/actionBarSizeandroid:background?attr/colorPrimaryapp:popupThemestyle/AppTheme.PopupOverlay //android.support.design.widget.AppBarLayoutinclude layoutlayout/content_main /android.support.design.widget.FloatingActionButtonandroid:idid/predictandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:layout_gravitybottom|endandroid:layout_margindimen/fab_marginapp:srcCompatandroid:drawable/ic_media_play / /android.support.design.widget.CoordinatorLayout /res/layout/content_main.xml ?xml version1.0 encodingutf-8? android.support.constraint.ConstraintLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentapp:layout_behaviorstring/appbar_scrolling_view_behaviortools:context.MainActivitytools:showInlayout/activity_mainScrollViewandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentLinearLayoutandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:orientationverticalTextViewandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:textSize30dpandroid:layout_marginBottom30dpandroid:textClick the Red-Colored floating button below to show and predict the image/ImageViewandroid:layout_widthmatch_parentandroid:layout_heightwrap_contentandroid:adjustViewBoundstrueandroid:scaleTypefitCenterandroid:idid/imageviewandroid:layout_marginBottom10dp/TextViewandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:idid/results//LinearLayout/ScrollView /android.support.constraint.ConstraintLayout2主活动类 主活动类相关代码如下 package com.specpal.mobileai; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; import android.os.Bundle; import android.renderscript.ScriptGroup; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.JsonReader; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import org.json.*; import org.tensorflow.contrib.android.TensorFlowInferenceInterface; import java.io.FileInputStream; import java.io.InputStream; public class MainActivity extends AppCompatActivity {//加载流推理库static {System.loadLibrary(tensorflow_inference);}//模型存放路径和输入/输出节点名称private String MODEL_PATH file:///android_asset/modelweights_22424.pb;private String INPUT_NAME zero_padding2d_1_input;private String OUTPUT_NAME output_1;private TensorFlowInferenceInterface tf;//保存预测的数组和图像数据的浮点值float[] PREDICTIONS new float[10];private float[] floatValues;private int[] INPUT_SIZE {150,150,3};ImageView imageView;TextView resultView;Snackbar progressBar;Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Toolbar toolbar (Toolbar) findViewById(R.id.toolbar);setSupportActionBar(toolbar);//初始化TensorFlowtf new TensorFlowInferenceInterface(getAssets(),MODEL_PATH);imageView (ImageView) findViewById(R.id.imageview);resultView (TextView) findViewById(R.id.results);progressBar Snackbar.make(imageView,PROCESSING IMAGE,Snackbar.LENGTH_INDEFINITE);final FloatingActionButton predict (FloatingActionButton) findViewById(R.id.predict);predict.setOnClickListener(new View.OnClickListener() {Overridepublic void onClick(View view) {try{//从ASSETS文件夹读取图片InputStream imageStream getAssets().open(testimage4.gif);Bitmap bitmap BitmapFactory.decodeStream(imageStream);imageView.setImageBitmap(bitmap);progressBar.show();predict(bitmap);}catch (Exception e){}}});}//计算最大预测及其置信度的函数public Object[] argmax(float[] array){int best -1;float best_confidence 0.0f;for(int i 0;i array.length;i){float value array[i];if (value best_confidence){best_confidence value;best i;}}return new Object[]{best,best_confidence};}public void predict(final Bitmap bitmap){//在后台线程中运行预测new AsyncTaskInteger,Integer,Integer(){Overrideprotected Integer doInBackground(Integer ...params){//将图像大小调整为150 x*150Bitmap resized_image ImageUtils.processBitmap(bitmap,150);//归一化像素floatValuesImageUtils.normalizeBitmap(resized_image,150,127.5f,1.0f);//将输入传到TensorFlowtf.feed(INPUT_NAME,floatValues,1,150,150,3);//计算预测tf.run(new String[]{OUTPUT_NAME});//将输出复制到预测数组中tf.fetch(OUTPUT_NAME,PREDICTIONS);//获得最高预测Object[] results argmax(PREDICTIONS);int class_index (Integer) results[0];float confidence (Float) results[1];try{final String conf String.valueOf(confidence * 100).substring(0,5);//将预测的类别索引转换为实际的标签名称final String label ImageUtils.getLabel(getAssets().open(labels.json),class_index);//展示结果runOnUiThread(new Runnable() {Overridepublic void run() {progressBar.dismiss();resultView.setText(label : conf %);}});}catch (Exception e){}return 0;}}.execute(0);} }相关其它博客 基于VGG-16AndroidPython的智能车辆驾驶行为分析—深度学习算法应用(含全部工程源码)数据集模型一 基于VGG-16AndroidPython的智能车辆驾驶行为分析—深度学习算法应用(含全部工程源码)数据集模型二 基于VGG-16AndroidPython的智能车辆驾驶行为分析—深度学习算法应用(含全部工程源码)数据集模型四 工程源代码下载 详见本人博客资源下载页 其它资料下载 如果大家想继续了解人工智能相关学习路线和知识体系欢迎大家翻阅我的另外一篇博客《重磅 | 完备的人工智能AI 学习——基础知识学习路线所有资料免关注免套路直接网盘下载》 这篇博客参考了Github知名开源平台AI技术平台以及相关领域专家DatawhaleApacheCNAI有道和黄海广博士等约有近100G相关资料希望能帮助到所有小伙伴们。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/89920.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

梅州公司做网站建设网站的协议范本

文章目录 前言1. 开启SSH服务2. Deppin安装Cpolar3. 配置ssh公网地址4. 公网远程SSH连接5. 固定连接SSH公网地址6. SSH固定地址连接测试 前言 Deepin操作系统是一个基于Debian的Linux操作系统,专注于使用者对日常办公、学习、生活和娱乐的操作体验的极致&#xff0…

东莞建站公司快荐全网天下特别好网站开发项目标书

RATM: RECURRENT ATTENTIVE TRACKING MODEL ICLR 2016 本文主要内容是 结合 RNN 和 attention model 用来做目标跟踪。 其中模型的组成主要是: 1. an attention model 主要用来从输入图像中提取 patch; 2. RNN 用来预测 attention 参数,即&am…

网站网址模板360免费建站李梦

在使用Mac电脑时,为了安全很多用户通常都会设置管理员密码。不过如果不小心忘记Mac管理员密码怎么办?幸运的是,有些方法可以重置Mac密码并重新获得访问权限。下面小编就教给大家几种重置用户密码的方法。未开启FileVault的用户方法一&#xf…

淘客做自己的网站c2c电商平台有哪些家

文章目录 前言一、概述二、系列文章全目录三、实验环境总结前言 通过本次 Java EE 三大框架(Spring、Spring MVC、MyBatis)原理、技术和方法的整合,大量的项目实践实际动手能力,解决总结在 SSM 项目中存在的问题,为毕业设计以及后期从事 Java 相关开发工作打下坚实的基础。…

包装回收网站建设网站 演示代码

ES & Kibana windows 安装 声明: 本文没有实际操作过,只记录。具体操作请参考 ES & Kibana 安装 该文章 JDK1.8,最低要求!ElasticSearch客户端,界面工具! Java开发,ElasticSearch的版…

做犯法任务的网站西安东郊做网站

目录 Disruptor简介 Disruptor的设计方案 RingBuffer数据结构 一个生产者单线程写数据的流程 多个生产者写数据的流程 消费者读数据 多个生产者写数据 Disruptor核心概念 Disruptor的使用 单生产者单消费者模式 单生产者多消费者模式 多生产者多消费者模式 消费者…

网站建设功能列表ps怎么做网站

目录 51.银行系中有很多恒星,H 君晚上无聊,便爬上房顶数星星,H 君将整个银河系看做一个平面,左上角为原点(坐标为(1, 1))。现在有 n 颗星星,他给每颗星星都标上坐标&…

入侵网站做排名辽宁咨发建设监理预算咨询有限公司网站

在图像分类任务中,卷积神经网络(CNN)相比于前馈神经网络(Feedforward Neural Network)具有以下优势: 局部感知能力:CNN通过使用卷积层和池化层来捕捉图像中的局部特征。卷积操作可以有效地共享参…

响应式网站建设精英北京市建筑工程设计有限责任公司

Windows下使用AndroidStudio及CMake编译Android可执行程序或静态库动态库 文章目录 Windows下使用AndroidStudio及CMake编译Android可执行程序或静态库动态库一、前言二、编译环境三、示例C/CPP程序1、总体工程结构2、示例代码3、CMakeLists.txt(重要)4、…

咸阳做网站哪里建网站性价比高

JAVA经典算法跪求关注,祝关注我的人都:身体健康,财源广进,福如东海,寿比南山,早上贵子,从不掉发!更多java资料可以私信我领取!【程序1】 题目:古典问题:有一对…

信托公司网站建设大宗交易网登录

为帮助小伙伴们更好的快速熟悉了解ACM32G103系列的特性,航芯特别发起了该系列开发板评测试用,以帮助大家更好地运用MCU进行项目设计。 ACM32G103开发板介绍 ACM32G103系列是航芯推出的一款有着丰富模拟外设及安全存储扩展能力的高性价比通用MCU。 高性…

浙江英文网站建设佛山微商网站建设

https://github.com/Miraclelucy/dive_into_deep_learning/tree/main 上面是别人的笔记 可以学一下。 如果没有梯子,按照清华源配置 清华源conda配置 最好下载 1.11版本torch那一套 然后装d2l版本可以装 pip install d2l0.17.6然后可以用 http://localhost:8889/…

高端建站做外贸 用国内空间做网站

BIOS(基本输入/输出系统)是被固化在计算机CMOS RAM芯片中的一组程序,为计算机提供最初的、最直接的硬件控制。正确设置BIOS可大大提高系统性能。技嘉主板bios设置方法是什么,很多人很多时候都需要进入bios设置,对于电脑高手来说,这…

wordpress 建视频网站网站怎么做反向代理

前言 续鼠标类设计之1,前面解决了鼠标信号问题,这里解决显示问题 引入 鼠标伴随操作系统而生,考虑在屏幕上怎样显示 思路 1>鼠标显示是一个动态效果,所以需要一个“动态效果类”对象,添加进鼠标类的属性里。 在面…

一键建站哪家信誉好口碑好的网站建设服务

这个项目是我一个盆友的毕业设计,他的设计在这项目基础上新增了功能,晚上我们在这部分讨论了很久,在机器学习领域这个项目不算高深,但对于我们初学者,想了解机器学习是个什么鬼东西的我们来说帮助很大。https://github…

驻马店专业做网站公司企业网站建立流程的第一步是什么

远程工作绝对是未来的趋势。 不管是全职还是兼职,远程办公更加提供了更加自由的工作环境,再好的办公环境有家里舒服吗🐶? 而现在所有远程办公的平台,目前对新手最友好的,我个人觉得是云队友平台。 不仅提供…

福建得兴建设工程网站腾讯云如何做网站

迭代器和生成器---- 迭代器协议和for循环工作机制1.迭代器协议:对象必须提供一个next方法,执行该方法要么返回迭代中的下一项,要么引起一个Stoplteration异常,以终止迭代(只能往后走,不能往前走&#xff09…

做h的游戏视频网站广州外贸网站公司

k柱汉诺塔 题目描述 汉诺塔(Hanoi Tower),又称河内塔。 传说大梵天创造世界的时候做了三根金刚石柱子,按左、中、右排序。大梵天在左侧的柱子上,从下往上按照大小顺序摞着64片黄金圆盘,越靠下的圆盘越大。…

软装设计培训一般多少钱seo是什么意思啊电商

今天,有人问我是否知道摆脱JavaFX控件(分别是按钮)的焦点突出的方法: 有关此问题的大多数文章和提示建议添加: .button:focused {-fx-focus-color: transparent; }但是使用这种样式,仍然会留下这样的光芒…