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 augmentationrandom-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 abovecsv:以上脚本生成的注释文件

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中的变量怎么读取

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

  1. freemarker中boolean变量的读取

    读取其它变量的时候可以直接用${变量名}来读取,但是当读取布尔类型的变量时,这种读取的方法就不行了会报错,得用以下这种方式 <input type="hidden" id=& ...

  2. 算法求解中的变量、数组与数据结构(STL 中的容器)

    本质上算法都是对数据的操作,没有数据,没有存储数据的容器和组织方式,算法就是无源之水无本之木,就是巧妇也难为无米之炊.算法是演员,变量.数组.容器等就是舞台, 然后整个算法的处理流程,都是针对这些数据 ...

  3. C语言中的变量底部下划线表示什么,编程中的下划线是什么意思?

    下划线在C没有特殊含义.一般在命名变量和方程用作断字符:integerarray,这样命名变量会很难看,一般会:integerArray 或者integer_array这样命名.一些程序包会经常看到: ...

  4. python中静态变量和静态方法_python类和函数中使用静态变量的方法

    本文实例讲述了python类和函数中使用静态变量的方法.分享给大家供大家参考.具体分析如下: 在python的类和函数(包括λ方法)中使用静态变量似乎是件不可能[Nothing is impossib ...

  5. 计算机中的变量和函数是什么意思,计算机中的变量和函数是什么意思?

    2019-03-13 回答 if 全部显示 全部隐藏 根据对指定的条件计算结果为true或false,返回不同的结果. 可以使用if对数值和公式执行条件检测. 语法 if(logical_test,v ...

  6. 顺风详解Nginx系列—Ngx中的变量

    在计算机语言中,变量是用来存储和表示数据的,但不同的语言表示变量的方式不同,像java语言会把变量抽象成各种类型,并且每种类型都会用一个特殊的符号表示,比如表示一个整数需要这样: int age= 2 ...

  7. Smarty中的变量

    Smarty中变量分为三类 1.PHP分配的变量 index.php [php] view plaincopy print? require('./include.php');   //加载Smart ...

  8. 在php中函数名称区分大小写吗,PHP中的变量名,函数名,类名是区分大小写的吗...

    在javascript中关于变量与函数的提升 在javascript中关于变量与函数的提升 一.简介 在javascript中声明变量与函数的执行步骤: 1.先预解析变量或函数声明代码,会把用var声 ...

  9. Oracle入门(十四.4)之在PL / SQL中使用变量

    一.变量的使用 (1)使用变量的原因 •临时存储数据 •储存值的操作 •可重用性 (2)处理PL / SQL中的变量 变量是: •在声明部分声明并初始化 •在可执行部分中使用并分配新值 变量可以是: ...

最新文章

  1. 开源的悲哀——袁萌100天变身实录[2]
  2. 【ArcGIS风暴】什么是点云?什么是Las数据集?一篇文章告诉你点云数据的奥秘
  3. Node.js Path 模块
  4. python 网页调试_使用Django 2.0构建Python Restful Web服务:七)在浏览器中浏览和调试restful接口...
  5. ajax post请求发送数组后台接收
  6. myeclipse文档链接oracle,[数据库]MyEclipse 连接Oracle数据库(初学者必看)
  7. linux电子教室软件,在Deepin Linux系统下安装和设置Veyon多媒体电子教室的方法
  8. HowNet介绍及相关API的使用方法
  9. MAML: meta learning 论文分析
  10. LOL英雄联盟打不了文字,打字就一闪一闪的,英文可以,解决方式
  11. 传奇服务器攻城文件,仿盛大传奇沙巴克攻防战与比奇怪物攻城说明
  12. centos上部署rap2
  13. 触摸屏计算机技术参数,触摸屏硬件安装—— 触摸屏参数设置
  14. chrome插件开发总结
  15. js为什么设置为单线程,怎么实现多线程
  16. Ubuntu Mint Installation Guide
  17. 高级程序语言c 平时作业,东北大学20秋学期《高级语言程序设计基础X》在线平时作业3...
  18. Sendrawpdu—Iphone短信欺骗工具发布下载
  19. 2840页的计算机毕业论文!德州奥斯汀华人博士究竟写了啥?
  20. 酷q服务器信息获取,酷Q获取加群QQ等级的解决方案

热门文章

  1. Flutter专题1-环境搭建
  2. iOS SwiftUI篇-2 UI控件 Text Button Image List
  3. docker logstash_用于监视Kubernetes和Docker的六大开源工具
  4. JS 数组A有数组B的数据就删除
  5. 微信小程序 侧滑效果实现
  6. 阿里最强热修复:Sophix 超高速集成与踩坑
  7. iOS 进阶—— iOS内存管理
  8. 企业为什么要使用基于Docker的PaaS/CaaS平台
  9. PHP PSR-1 基本代码规范(中文版)
  10. 菜鸟物流云是如何帮助快递合作伙伴解决双11巨大业务负荷的?