Streamlit —使用數據應用程序更好地測試模型

介紹 (Introduction)

We use all kinds of techniques from creating a very reliable validation set to using k-fold cross-validation or coming up with all sorts of fancy metrics to determine how good our model performs. However, nothing beats looking at the raw output. When you look at sample output, you figure out things that none of the other methods can tell you.

我們使用各種技術,從創建非常可靠的驗證集到使用k倍交叉驗證或提出各種幻想指標來確定模型的性能。 但是,看原始輸出無所不能。 查看示例輸出時,您會發現其他方法無法告訴您的內容。

For example, if you are performing object detection on crops, you might see that when the crop is aligned in a certain way because of the wind, our bounding boxes don’t encapsulate the crop properly.

例如,如果要對農作物執行對象檢測,則可能會看到,由于風將農作物以某種方式對齊時,我們的邊界框無法正確封裝農作物。

However, looking at sample outputs is a tedious task. Say we want to test various NMS values, and we also want to test it on a bunch of images. We can always write a function for this, but running it, again and again, is boring.

但是,查看樣本輸出是一項繁瑣的任務。 假設我們要測試各種NMS值,并且還要對一堆圖像進行測試。 我們總是可以為此編寫一個函數,但是一次又一次地運行它很無聊。

Wouldn’t it be nice to have an app where we can upload an image and use a slider to adjust the NMS value? Welcome, Streamlit.

擁有一個可以上傳圖像并使用滑塊調整NMS值的應用程序不是很好嗎? 歡迎,Streamlit。

Image for post

什么是Streamlit? (What is Streamlit?)

According to their website, Streamlit is an open-source web framework for data scientists and machine learning engineers to create beautiful, performant apps in just a few hours, all in pure Python.

根據他們的網站,Streamlit是一個開放源代碼Web框架,供數據科學家和機器學習工程師在短短幾個小時內使用純Python編寫漂亮,高性能的應用程序。

安裝 (Installation)

pip install streamlit

入門 (Getting started)

For this demo, I will be using the model I trained for wheat object detection using a FasterRCNN. You can go back to that article, train or, download my model and then follow along.

對于此演示,我將使用經過FasterRCNN訓練用于小麥對象檢測的模型 。 您可以返回該文章,進行培訓或下載我的模型,然后繼續學習。

Streamlit is just a standard python file run from top to bottom. We will start by creating a file called app.py, and writing the following code in it.

Streamlit只是從上到下運行的標準python文件。 我們將從創建一個名為app.py的文件開始,并在其中寫入以下代碼。

Image for post

We will run this as follows:

我們將如下運行:

streamlit run app.py

It will open up our browser with the following output.

它將打開我們的瀏覽器,并顯示以下輸出。

Image for post

Notice that we used a # inside st.write(). This indicates that we are writing markdown inside it. The first thing we need is a file uploader to upload images to Streamlit. Again, this is as simple as doing:

注意,我們在st.write()中使用了#。 這表明我們正在其中編寫markdown。 我們需要的第一件事是文件上傳器,將圖像上傳到Streamlit。 同樣,這很簡單:

Image for post

We pass the type of files allowed (jpg and png in this case), and when we do attach one, we read it using PIL. When we save app.py now:

我們傳遞允許的文件類型(在這種情況下為jpg和png),當我們附加一個文件時,我們使用PIL進行讀取。 當我們現在保存app.py時:

Image for post

we see that Streamlit identifies that the source file has changed and asks if we want to rerun. And we do. Hence, we select “always rerun” for change to reflect automatically. Now our browser looks like this:

我們看到Streamlit確定源文件已更改,并詢問是否要重新運行。 我們做。 因此,我們選擇“始終重新運行”進行更改以自動反映。 現在,我們的瀏覽器如下所示:

Image for post

To display the image, we can use st.image(). However, after generating predictions, we want to replace the input image with our predicted image. To do so, we create an empty container and display everything in it.

要顯示圖像,我們可以使用st.image()。 但是,在生成預測后,我們希望將輸入圖像替換為預測圖像。 為此,我們創建一個空容器并顯示其中的所有內容。

Image for post

Another thing I like about using a container is that you can set use_column_width = True, and you won’t have to worry about image resizing. Now we can drag and drop images into our app.

我喜歡使用容器的另一件事是,您可以設置use_column_width = True,而不必擔心圖像調整大小。 現在我們可以將圖像拖放到我們的應用程序中。

Image for post

Finally, we can convert our image to a tensor, load our model, generate outputs, and write it to our container.

最后,我們可以將圖像轉換為張量,加載模型,生成輸出,并將其寫入容器。

Image for post

To vary NMS values, we can either use a slider or an input box to type the value or use the ‘+’ and ‘-’ buttons to increase or decrease the value. I’m going to go with the slider. Our code changes to.

要更改NMS值,我們可以使用滑塊或輸入框鍵入值,也可以使用“ +”和“-”按鈕增大或減小值。 我將使用滑塊。 我們的代碼更改為。

Image for post

And that’s it. In about just 50 lines of code, we can create this super useful app to test our model. You can also create templates for various problems like image classification, segmentation, object detection, and so on and use them every time you train a new model.

就是這樣。 在大約50行代碼中,我們可以創建這個超級有用的應用程序來測試我們的模型。 您還可以針對各種問題(例如圖像分類,分割,對象檢測等)創建模板,并在每次訓練新模型時使用它們。

Finally, when we change the NMS values using the slider, if we’ve already generated predictions for a particular value, we don’t want to generate them again. Hence you can stick a simple decorator on top of the function:

最后,當我們使用滑塊更改NMS值時,如果我們已經生成了特定值的預測,則我們不想再次生成它們。 因此,您可以在該函數之上粘貼一個簡單的裝飾器:

Image for post

and it will cache the results for you. This way it won’t rerun the same threshold every time but just used the cached result. Cool, isn’t it?

它將為您緩存結果。 這樣,它不會每次都重新運行相同的閾值,而只是使用了緩存的結果。 不錯,不是嗎?

結論: (Conclusion:)

That will be it for this article. I would really recommend everyone to use Streamlit and create data apps. It works well for all kinds of data and caching helps with expensive operations like working with large data frames. Give it a try.

本文就是這樣。 我真的建議大家使用Streamlit并創建數據應用程序。 它適用于所有類型的數據,并且緩存有助于處理昂貴的操作,例如處理大型數據幀。 試試看。

If you want to learn more about deep learning check out my deep learning series.

如果您想了解有關深度學習的更多信息,請查看我的深度學習系列。

~happy learning

?快樂學習

翻譯自: https://towardsdatascience.com/streamlit-use-data-apps-to-better-test-your-model-4a14dad235f5

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390719.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390719.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390719.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Spring MVC Boot Cloud 技術教程匯總(長期更新)

昨天我們發布了Java成神之路上的知識匯總,今天繼續。 Java成神之路技術整理(長期更新) 以下是Java技術棧微信公眾號發布的關于 Spring/ Spring MVC/ Spring Boot/ Spring Cloud 的技術干貨,本文長期更新。 Spring 系列 Java 必看的…

X Window系統

X Window系統 一種以位圖方式顯示的軟件窗口系統。誕生于1984,比Microsoft Windows要早。是一套獨立于內核的軟件 Linux上的X Window系統 X Window系統由三個基本元素組成:X Server、X Client和二者通信的通道。 X Server:是控制輸出及輸入…

冒名頂替上大學羅彩霞_什么是冒名頂替綜合癥,您如何克服?

冒名頂替上大學羅彩霞冒名頂替綜合癥 (Imposter Syndrome) Imposter Syndrome is a feeling of being a fraud or not being good enough to get the job done. Its common among software engineers, developers and designers working in tech companies, especially those n…

Linux命令----用戶管理

修改用戶密碼: sudo passwd (當前)用戶名  【sudo是super user do的簡寫,passwd是password的簡寫】 顯示當前正在操作系統的用戶:whoami   顯示當前登錄系統的用戶信息:who am i 注意: 普通…

lasso回歸和嶺回歸_如何計劃新產品和服務機會的回歸

lasso回歸和嶺回歸Marketers sometimes have to be creative to offer customers something new without the luxury of that new item being a brand-new product or built-from-scratch service. In fact, incrementally introducing features is familiar to marketers of c…

python代碼

原始字符串,不做任何特殊的處理 print("Newlines are indicated by \n")#Newlines are indicated by print(r"Newlines are indicated by \n")#Newlines are indicated by \n 格式輸出,轉化為字符串由format自動完成 ag…

Linux 設備管理和進程管理

設備管理 Linux系統中設備是用文件來表示的,每種設備都被抽象為設備文件的形式,這樣,就給應用程序一個一致的文件界面,方便應用程序和操作系統之間的通信。 設備文件集中放置在/dev目錄下,一般有幾千個,不…

樂高ev3涉及到的一些賽事_使您成為英雄的前五名開發者技能(提示:涉及LEGO)

樂高ev3涉及到的一些賽事Programming is like building something with LEGOs. Any developer can pick up a brand new LEGO set and build it following the instructions. This is very easy. Think of it as coding school assignments or entry level tutorials.編程就像用…

貝葉斯 定理_貝葉斯定理實際上是一個直觀的分數

貝葉斯 定理Bayes’ Theorem is one of the most known to the field of probability, and it is used often as a baseline model in machine learning. It is, however, too often memorized and chanted by people who don’t really know what P(B|E) P(E|B) * P(B) / P(E…

winfrom 點擊按鈕button彈框顯示顏色集

1.窗體托一個按鈕button; 2.單擊事件: 1 private void btnForeColor_Click(object sender, EventArgs e)2 {3 using (ColorDialog cdialog new ColorDialog())4 {5 cdialog.AnyColor true;6 …

JavaScript時間事件:setTimeout和setInterval

Programmers use timing events to delay the execution of certain code, or to repeat code at a specific interval.程序員使用時序事件來延遲某些代碼的執行,或以特定的時間間隔重復代碼。 There are two native functions in the JavaScript library used to …

webservice 基本要點

webservice的特點 webservices是自我包含的 webservices是自我描述的 webservices是跨平臺和語言的 webservices是基于開放和標準的 webservices是可以組合的 webservices是松散耦合的 webservices提供編程訪問的能力 webservices通過網絡進行發布,查找和使用 發布w…

文本數據可視化_如何使用TextHero快速預處理和可視化文本數據

文本數據可視化自然語言處理 (Natural Language Processing) When we are working on any NLP project or competition, we spend most of our time on preprocessing the text such as removing digits, punctuations, stopwords, whitespaces, etc and sometimes visualizati…

Less變量

Less變量 定義變量 Less 中的變量和其他編程語言一樣,可以實現值的復用,同樣它也有作用域(scope)。簡單的講,變量作用域就是局部變量和全局變量的概念。 Less 中,變量作用域采用的是就近原則,換…

漸進式web應用程序_如何在漸進式Web應用程序中添加到主屏幕

漸進式web應用程序添加到主屏幕 (Add To Homescreen) Here the web app install banner is focused on web app, with the feature of add to homescreen.在此,Web應用程序安裝標語專注于Web應用程序,具有添加到主屏幕的功能。 瀏覽器對“添加到主屏幕”…

linux shell 編程

shell的作用 shell是用戶和系統內核之間的接口程序shell是命令解釋器 shell程序 Shell程序的特點及用途: shell程序可以認為是將shell命令按照控制結構組織到一個文本文件中,批量的交給shell去執行 不同的shell解釋器使用不同的shell命令語法 shell…

Leetcode之javascript解題(No33-34)

附上我的github倉庫,會不斷更新leetcode解題答案,提供一個思路,大家共勉 在我的主頁和github上可以看到更多的關于leetcode的解題報告!(因為不知道為什么掘金沒有將其發布出來,目前已經聯系掘金客服&#x…

真實感人故事_您的數據可以告訴您真實故事嗎?

真實感人故事Many are passionate about Data Analytics. Many love matplotlib and Seaborn. Many enjoy designing and working on Classifiers. We are quick to grab a data set and launch Jupyter Notebook, import pandas and NumPy and get to work. But wait a minute…

轉:防止跨站攻擊,安全過濾

轉:http://blog.csdn.net/zpf0918/article/details/43952511 Spring MVC防御CSRF、XSS和SQL注入攻擊 本文說一下SpringMVC如何防御CSRF(Cross-site request forgery跨站請求偽造)和XSS(Cross site script跨站腳本攻擊)。 說說CSRF 對CSRF來說,其實Spring…

Linux c編程

c語言標準 ANSI CPOSIX(提高UNIX程序可移植性)SVID(POSIX的擴展超集)XPG(X/Open可移植性指南)GNU C(唯一能編譯Linux內核的編譯器) gcc 簡介 名稱: GNU project C an…