当前位置: 首页 > 编程日记 > 正文

colab中的变量怎么读取_Fizyr Retinanet在Colab中进行目标检测

colab中的变量怎么读取

by RomRoc

由RomRoc

带有Fizyr Retinanet的Google Colab中的对象检测 (Object Detection in Google Colab with Fizyr Retinanet)

Let’s continue our journey to explore the best machine learning frameworks in computer vision.

让我们继续我们的旅程,探索计算机视觉中最好的机器学习框架。

In the first article we explored object detection with the official Tensorflow APIs. The second article was dedicated to an excellent framework for instance segmentation, Matterport Mask R-CNN based on Keras.

在第一篇文章中,我们探讨了使用官方Tensorflow API进行对象检测。 第二篇文章致力于一个很好的实例分割框架,基于Keras的Matterport Mask R-CNN。

In this article we examine Keras implementation of RetinaNet object detection developed by Fizyr. RetinaNet, as described in Focal Loss for Dense Object Detection, is the state of the art for object detection.The object to detect with the trained model will be my little goat Rosa.

在本文中,我们研究由Fizyr开发的RetinaNet对象检测的Keras实现 。 RetinaNet,如密集物体检测的焦点损失中所述,是物体检测的最新技术。使用训练模型进行检测的物体将是我的小山羊Rosa。

The colab notebook and dataset are available in my Github repo.

我的Github存储库中提供了colab笔记本和数据集。

In this article, we go through all the steps in a single Google Colab netebook to train a model starting from a custom dataset.

在本文中,我们将在单个Google Colab上网本中完成所有步骤,以训练从自定义数据集开始的模型。

We will keep in mind these principles:

我们将牢记以下原则:

  • illustrate how to make the annotation dataset

    说明如何制作注释数据集
  • describe all the steps in a single Notebook

    在一个笔记本中描述所有步骤
  • use free software, Google Colab and Google Drive, so it’s based exclusively on free cloud resources

    使用免费软件,Google Colab和Google云端硬盘,因此它完全基于免费的云资源

At the end of the article you will be surprised by the simplicity of use and the good results we will obtain through this object detection framework.

在本文的结尾,您将对使用的简单性以及通过此对象检测框架获得的良好结果感到惊讶。

Despite its ease of use, Fizyr is a great framework, also used by the winner of the Kaggle competition “RSNA Pneumonia Detection Challenge”.

尽管使用方便,但Fizyr是一个很好的框架, Kaggle竞赛 “ RSNA肺炎检测挑战赛”的获胜者也使用了该框架。

制作数据集 (Making the dataset)

We start by creating annotations for the training and validation dataset, using the tool LabelImg. This excellent annotation tool let you quickly annotate the bounding boxes of the objects to train the machine learning model.

我们首先使用工具LabelImg为训练和验证数据集创建注释。 这个出色的注释工具可让您快速注释对象的边界框,以训练机器学习模型。

LabelImg creates annotations in PascalVoc format, so we need to convert annotations to Fizyr format:

LabelImg以PascalVoc格式创建注释,因此我们需要将注释转换为Fizyr格式:

  • create a zip file containing training dataset images and annotations with the same filename (check my example dataset in Github)

    创建一个zip文件,其中包含具有相同文件名的训练数据集图像和注释(请在Github中查看我的示例数据集)
objdet_dataset.zip|- img1.jpg|- img1.xml|- img2.jpg|- img2.xml...
  • Upload zip file in Google Drive, get Drive file id, and substitute the DATASET_DRIVEID value

    在Google云端硬盘中上传zip文件,获取云端硬盘文件ID,然后替换DATASET_DRIVEID值
  • Run cell that iterates over the xml files and creates annotations.csv file

    运行在xml文件上迭代并创建annotations.csv文件的单元格

Note: you can see my answer on Stackoverflow to get the Drive file id.

注意:您可以在Stackoverflow上查看我的答案以获取驱动器文件ID。

模型训练 (Model training)

Model training is the core of the notebook. Fizyr offers various parameters, described in Github, to run and optimize this step.

模型训练是笔记本的核心。 Fizyr提供了各种参数(如Github中所述 )来运行和优化此步骤。

It’s a good option to start from a pretrained model instead of training a model from scratch. Fizyr released a model based on ResNet50 architecture, pretrained on Coco dataset.

从预训练的模型开始而不是从头开始训练模型是一个很好的选择。 Fizyr发布了基于ResNet50架构的模型,该模型在Coco数据集上进行了预训练。

URL_MODEL = 'https://github.com/fizyr/keras-retinanet/releases/download/0.5.0/resnet50_coco_best_v2.1.0.h5'

We can even use our pretrained model, and continue the training from it. This option is particularly useful to train for some epochs, so save it in Google Drive, and later restart the training from the saved model. In this way we can bypass the 12-hour execution limit in Colab, and we can train the model for many epochs.

我们甚至可以使用我们的预训练模型,并从中继续训练。 此选项对于某些时期的训练特别有用,因此请将其保存在Google云端硬盘中,然后再从保存的模型中重新开始训练。 通过这种方式,我们可以绕过Colab中12小时的执行限制,并且可以针对许多时期训练模型。

From my tests, a high value of batch_size and steps offers better results, but they greatly increase the execution time of each epoch.

根据我的测试,batch_size和steps的值较高可以提供更好的结果,但是它们大大增加了每个纪元的执行时间。

We can start training from our custom dataset with:

我们可以从我们的自定义数据集中开始训练:

!keras_retinanet/bin/train.py --freeze-backbone --random-transform --weights {PRETRAINED_MODEL} --batch-size 8 --steps 500 --epochs 10 csv annotations.csv classes.csv

Let’s analyze each argument passed to the script train.py.

让我们分析传递给脚本train.py的每个参数。

  • freeze-backbone: freeze the backbone layers, particularly useful when we use a small dataset, to avoid overfitting

    冻结主干:冻结主干层,当我们使用较小的数据集时特别有用,以避免过度拟合
  • random-transform: randomly transform the dataset to get data augmentation

    random-transform:随机变换数据集以获得数据扩充
  • weights: initialize the model with a pretrained model (your own model or one released by Fizyr)

    权重:使用预先训练的模型(您自己的模型或Fizyr发布的模型)初始化模型
  • batch-size: training batch size, higher value gives smoother learning curve

    批处理大小:训练批处理大小,更高的值可提供更平滑的学习曲线
  • steps: number of steps for epochs

    步骤:纪元的步骤数
  • epochs: number of epochs to train

    纪元:要训练的纪元数
  • csv: annotations files generated by the script above

    csv:以上脚本生成的注释文件

The training process output contains a description of layers and loss metrics during training, and as you can see, loss metrics decrease during each epoch:

训练过程的输出包含训练期间的层和损耗度量的描述,如您所见,损耗度量在每个时期都会减少:

Using TensorFlow backend....Layer (type)                    Output Shape         Param #     Connected toinput_1 (InputLayer)            (None, None, None, 3 0padding_conv1 (ZeroPadding2D)   (None, None, None, 3 0           input_1[0][0]                    ...Total params: 36,382,957Trainable params: 12,821,805Non-trainable params: 23,561,152NoneEpoch 1/10500/500 [==============================] - 1314s 3s/step - loss: 1.0659 - regression_loss: 0.6996 - classification_loss: 0.3663Epoch 2/10500/500 [==============================] - 1296s 3s/step - loss: 0.6747 - regression_loss: 0.5698 - classification_loss: 0.1048Epoch 3/10500/500 [==============================] - 1304s 3s/step - loss: 0.5763 - regression_loss: 0.5010 - classification_loss: 0.0753
Epoch 3/10500/500 [==============================] - 1257s 3s/step - loss: 0.5705 - regression_loss: 0.4974 - classification_loss: 0.0732

推理 (Inference)

The last step performs inference of test images with the trained model.The Fizyr framework allows us to perform inference using CPU, even if you trained the model with GPU. This feature is important in typical production environments, where people usually opt for less expensive hardware infrastructures for inference, without GPUs.

最后一步是使用经过训练的模型执行测试图像的推断。即使您使用GPU训练了模型,Fizyr框架也允许我们使用CPU进行推断。 此功能在典型的生产环境中很重要,在该环境中,人们通常选择较便宜的硬件基础架构来进行推理,而无需使用GPU。

Let’s examine the following lines in detail:

让我们详细研究以下几行:

model_path = os.path.join('snapshots', sorted(os.listdir('snapshots'), reverse=True)[0])print(model_path)
# load retinanet modelmodel = models.load_model(model_path, backbone_name='resnet50')model = models.convert_model(model)

The first line sets the model file as the last model generated by the training process in /snapshots directory. Then the model is loaded from the filesystem and converted to run inference.

第一行将模型文件设置为/ snapshots目录中训练过程生成的最后一个模型。 然后,从文件系统加载模型并转换为运行推理。

You can change the values of THRES_SCORE, which represents the confidence threshold to show an object detection.

您可以更改THRES_SCORE的值,该值表示显示对象检测的置信度阈值。

结论 (Conclusions)

We went through the complete journey to make object detection with Fizyr implementation of RetinaNet. We created a dataset, trained a model, and ran inference (here is my Github repo for the notebook and dataset).

我们经历了使用RetinaNet的Fizyr实现进行对象检测的完整过程。 我们创建了一个数据集,训练了一个模型,然后进行了推断( 这是我的笔记本和数据集的Github存储库)。

I was impressed by the following aspects of this excellent framework:

这个出色的框架在以下方面给我留下了深刻的印象:

  • this framework is easy to use to get good inference, even without much customization

    即使没有太多定制,该框架也易于使用以获得良好的推断

  • it was simple to transform annotations to Fizyr’s dataset format, compared to other frameworks.

    与其他框架相比, 将注释转换为Fizyr的数据集格式很简单

In general Fizyr is a good choice to start an object detection project, in particular if you need to quickly get good results.

通常,Fizyr是启动对象检测项目的不错选择,尤其是在需要快速获得良好结果的情况下。

If you enjoyed this article, leave a few claps, it will encourage me to explore further machine learning opportunities :)

如果您喜欢这篇文章,请留下一些鼓掌,它会鼓励我探索更多的机器学习机会:)

翻译自: https://www.freecodecamp.org/news/object-detection-in-colab-with-fizyr-retinanet-efed36ac4af3/

colab中的变量怎么读取

相关文章:

c++重载(以运算符重载为主)

重载(OverLoading)是面向对象程序设计多态性的一种体现。所谓重载,是指“同一标识符”在同一作用域的不同场合具有不同的语义,这个标识符可以是函数名或运算符。也就是说,重载可以使多个函数使用同一个函数名&#xff…

记录-MySQL中的事件调度Event Scheduler

下面是自己的实例 /*查询event是否开启(查询结果Off为关闭 On为开启)*/show variables like %sche%; /*开启/关闭命令(1开启--0关闭)*/set global event_scheduler1; /*关闭事件任务: */alter event e_test_insert ON COMPLETION…

JS 实现下载Blod文件

实现代码: //下载Blod文件 const downLoadBlobFile (filename, res) > {if (!res) return;let a document.createElement(a);let blob new Blob([res], { type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charsetutf-8 });let blo…

盖尔-沙普利算法_盖尔定律-及其与初创企业的关系

盖尔-沙普利算法I realized something fascinating the other day: I realized that, as a startup entrepreneur and founder, I’m a builder of systems.前几天,我意识到了一件令人着迷的事情:我意识到,作为一名初创企业家和创始人&#x…

使用VS Code开发.Net Core 2.0 MVC Web应用程序教程之三(配置文件读取)

干了一天的活,还有点时间,给兄弟们写点东西吧。 大家有没有发现一个问题?那就是在.Net Core的MVC项目里面,没有.config文件了!!!同志们,没有config文件了啊,这样搞&#…

小程序云开发数据库在网站读取

使用TCB JS SDK Tencent Cloud Base(TCB) JavaScript SDK 介绍 TCB 提供开发应用所需服务和基础设施。TCB JS SDK 让你可以在网页端使用 JavaScript 代码服务访问 TCB 的的服务。你可以使用该 SDK 构建自己的公众号页面或者独立的网站等 Web 服务。 安装 TCB JS SDK 可以…

设计模式学习心得4

1.组合模式 定义一个父类,其中包括所有子类的方法接口,那么对于任何一个子类来说对外界都是封闭的,外界只调用父类的接口,而不知道子类是否有实现。 2.迭代器模式 这个很常见,在C中常常会用在标准模版类中,…

react创建组件_如何使用React创建时间轴组件

react创建组件These days I’ve been working on a new page for my website. I wanted to have a Timeline to showcase some of my professional accomplishments over the years.这些天来,我一直在为网站创建新页面。 我希望有一个时间表来展示我多年来的一些专业…

oracle根据一张表更新另外一张表

知道是两张表进行更新,之前作过mysql的,直接就写了: update a,b set a.code b.code wehre a.id b.id 然后就报错了,上网查了下知道oracle不能这样子写 之后找到如下的办法: UPDATE a set a.code (select b.code from b where…

应用内设置语言不重启方法

1、设置本应用方法网上有很多,大概如下 Resources resources getResources(); Configuration config resources.getConfiguration(); DisplayMetrics dm resources.getDisplayMetrics(); config.locale locale; //目标语言 resources.updateConfiguration(confi…

小程序内容审核违规过滤,在小程序使用security.msgSecCheck

使用微信提供的API security.msgSecCheck 查看文档 1.开通云开发,创建云环境。 2.在云函数的目录中,创建一个云函数(ContentCheck),如果小程序代码没有云函数的目录,可以在 project.config.json 目录中配置…

如何在JavaScript中切片和拼接数组

.slice() and .splice() are similar methods in JavaScript. They look similar, they sound similar, and they do similar things. For those reasons, it’s important to know the differences between them. Also, they’re used very often, so understanding their usa…

jQuery中getJSON跨域原理详解

详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcytp28 jQuery中getJSON跨域原理详解 前几天我再开发一个叫 河蟹工具条 的时候,其中有个功能就是获取本页面的短网址。 这个想法是好的,可是在我付诸于行动的时候,发…

样式集(七)仿微信发现页样式

效果图&#xff1a; <!--pages/find/find.wxml--><include src"/components/common/common" /> <view class"item" catchtap"nav1"><image class"icon" mode"widthFix" src"/images/icon_5.png&q…

html向js传递id

html获取id方法&#xff1a; <div id"thediv1" style"display:block" onclick"ceshi(this.id)">技术A组</div> this.id ------>本身id转载于:https://www.cnblogs.com/wanlibingfeng/p/7613575.html

javascript功能_功能性JavaScript简介

javascript功能Hey everybody! I’ve written a book called Discover Functional JavaScript, and it’s now ready in both paperback and Kindle formats.大家好&#xff01; 我已经写了一本书《 发现功能JavaScript》 &#xff0c;现在已经可以使用平装本和Kindle格式。 A…

样式集,小程序群聊,聊天室样式,效果图

效果图 注&#xff1a;&#xff08;码云 group_chat_yun &#xff09; 代码&#xff1a; <!-- <view class"top"><image class"page_editright" catchtap"navBack" mode"widthFix" src"/images/editright.png&quo…

GeoQuiz项目的开发与总结2

时间过得很快&#xff0c;第二阶段的学习结束了。 本周的主要工作是完成了Geoquiz项目的剩余部分。 首先是学到了些什么&#xff0c;最主要的是工作的流程&#xff0c;然后是界面的布局&#xff0c;菜单栏的设计到等。当然我觉得我学到的应该是工作制作的思维方式吧。 再来说说…

【12.16】VC++调用Word OLE进行自动化生成报表

&#xff01; 12-16更新 初始化博客转载于:https://www.cnblogs.com/miki-52/p/5052689.html

python timber_如何使用Timber更有效地记录日志

python timberby Ayusch Jain通过Ayusch Jain 如何使用Timber更有效地记录日志 (How to log more efficiently with Timber) Logging is one of the most used utilities in the Android framework. It is really helpful in debugging your code when debugging by break-poi…

node 实现blog博客

https://cnodejs.org/topic/581b0c4ebb9452c9052e7acb转载于:https://www.cnblogs.com/zhangshuda/p/7640363.html

小程序输入框导致界面上移,在输入的时候固定住页面的解决代码

效果&#xff1a; 代码&#xff1a; <view class"comment" style"bottom:{{bottom}}px"><view class"emoji_block" wx:if{{emoji_block_show}}><view wx:for{{connectemoji}} catchtap"add_biaoqing" id"{{item}}…

react中纯函数_如何在纯React中创建电子邮件芯片

react中纯函数by Andreas Remdt由Andreas Remdt 如何在纯React中创建电子邮件芯片 (How to create email chips in pure React) Imagine that you, the good-looking developer (yes, I’m talking to you!), want to build an invitation form where users can add one or mo…

servlet程序HTTP Status 500 - Error instantiating servlet class 解决

一、项目存放路径问题(最常见) 在安装Tomcat时&#xff0c;运行程序都正常&#xff0c;但却打不开http://localhost:8080/&#xff0c;在Tomcat目录webapps下也找不到自己做的项目&#xff0c;这时因为你做的项目没有部署到webapps目录下&#xff0c;倒霉的时候就会遇到报错HTT…

ASP.NET将原始图片按照指定尺寸等比例缩放显示图片

网站上可能会有很多图片&#xff0c;比如产品图片等&#xff0c;而且他们可能大小不一&#xff0c;宽度和高度也不一定一样&#xff0c;有的很大有的很小。如果放在一张网页上&#xff0c;可能会破坏版面&#xff0c;但是如果强制让他们按照指定的宽度和高度显示&#xff0c;因…

前端开发框架选择

Vue Vant 适用场景&#xff1a;开发移动端 (vue) 上手难度&#xff1a;1 Vant是一款很好用的移动端UI框架&#xff0c;非常轻便&#xff0c;适合小型项目 https://vant-contrib.gitee.io/vant/#/zh-CN/ 微信小程序 适用场景&#xff1a;微信小程序&#xff08;小程序原生框架…

anki_Anki如何挽救我的工程生涯

ankiby Jeffrey Shek通过Jeffrey Shek Anki如何挽救我的工程生涯 (How Anki saved my Engineering Career) I was burned out and my software career was stalling just three years in. My memory sucked. Was my poor memory from stress, lack of sleep or was it always …

信息安全系统设计基础期末总结

【博客汇总】 一、每周读书笔记链接汇总 •[第二周读书笔记] http://www.cnblogs.com/20135302wei/p/4842480.html •[第三周读书笔记] http://www.cnblogs.com/20135302wei/p/4858760.html •[第四周读书笔记] http://www.cnblogs.com/20135302wei/p/4870113.html •[第五周读…

方法 retrun 异步的值,创建一个变量直接等于一个异步方法返回的值

需求&#xff1a;我想创建一个变量&#xff0c;他的值是一个openid&#xff0c; openid 从 getOpenid (封装的一个异步方法) 里面返回&#xff0c;通常调用 getOpenid ,会返回一个Promise 对象&#xff0c;.then 之后才能得到值&#xff0c;例如&#xff1a; //模拟一个异步方…

ps混合模式glsl代码

https://github.com/jamieowen/glsl-blend 转载于:https://www.cnblogs.com/guochen/p/7645227.html