lr模型和dnn模型_建立ML或DNN模型的技巧
lr模型和dnn模型
機器學習 (Machine Learning)
Everyone can fit data into any model machine learning or deep learning frameworks easily. Following the best practices may help you to distinguish others. Also, you may consider the following tricks. Here are some methods that I applied during my data scientists’ journey.
每個人都可以輕松地將數據放入任何模型機器學習或深度學習框架中。 遵循最佳做法可能會幫助您與眾不同。 另外,您可以考慮以下技巧。 這是我在數據科學家旅途中應用的一些方法。
表中的內容 (Table of Content)
Data Preparation
資料準備
- Process Your Own Data 處理您自己的數據
- Use Tensor 使用張量
- Data Augmentation 數據擴充
- Sampling Same Data 采樣相同數據
Model Training
模型訓練
- Saving Intermediate Checkpoint 保存中間檢查點
- Virtual Epoch 虛擬時代
- Simple is Beauty 簡單就是美
- Simplifying Problem 簡化問題
Debugging
調試
- Simplifying Problem 簡化問題
- Using Eval Mode for Training 使用評估模式進行訓練
- Data Shifting 數據轉移
- Addressing Underfitting 解決擬合不足
- Addressing Overfitting 解決過度擬合
Production
生產
- Meta Data Association 元數據協會
- Switch to Inference Mode 切換到推理模式
- Scaling Cost 縮放成本
- Stateless 無狀態
- Batch Process 批處理
- Use C++ 使用C ++
資料準備 (Data Preparation)
處理您自己的數據 (Process Your Own Data)
Photo by Oliver Hale on Unsplash 奧利弗·黑爾 ( Oliver Hale)在Unsplash上攝It will be suggested to handle data processing within a model (or within prediction service). The reason is a consumer may not know how to do that and making feature engineering transparent to them.
建議在模型(或預測服務)中處理數據處理。 原因是消費者可能不知道該怎么做以及使功能工程對他們透明。
Taking a text classification problem as an example, and you are using BERT for classification. You cannot ask your client to make the tokenization and feature conversations (converting text to token ID).
以文本分類問題為例,您正在使用BERT進行分類。 您不能要求客戶進行標記化和功能對話(將文本轉換為標記ID)。
Taking a regression problem as an example and date (e.g., 10/31/2019) is one of the features. In your initial model, you may only use the day of the week (i.e., Thursday) as a feature. After several iterations, the day of the week is no longer a good feature, and you want to use day (i.e., 31) only. If your client only passes the date (i.e., 10/31/2019) instead of a day of the week (i.e., 31) from day 1, you do not need to change the API interface in order to roll out a new model.
以回歸問題為例和日期(例如10/31/2019)是功能之一。 在初始模型中,您只能將星期幾(即星期四)用作功能。 經過幾次迭代之后,星期幾不再是一個好功能,您只想使用day(即31)。 如果您的客戶僅通過日期(即10/31/2019)而不是從第1天起的一周中的某一天(即31),則無需更改API接口即可推出新模型。
Taking automatic speech recognition as an example, a consumer can only send audio to you but not classic features such as Mel Frequency Cepstral Coefficient (MFCC).
以自動語音識別為例,消費者只能向您發送音頻,而不能發送經典功能,例如梅爾頻率倒譜系數(MFCC)。
So it is suggested to embedding data preprocessing in your pipeline rather than asking your client to do it.
因此,建議將數據預處理嵌入到您的管道中,而不要讓您的客戶端來做。
使用張量 (Use Tensor)
Tensor is an N-dimensional array and optimizing for multidimensional calculation. It is faster than using Python dictionary or array, and the expected data format for a deep learning framework (e.g., PyTorch or TensorFlow) is tensor.
Tensor是一個N維數組,針對多維計算進行了優化。 它比使用Python字典或數組更快,并且深度學習框架(例如PyTorch或TensorFlow)的預期數據格式為張量。
數據擴充 (Data Augmentation)
Lack of labeled data is one of the challenges that practitioners usually deal with it. Transfer learning is one of the ways to overcome it. You can consider using ResNet (for computer vision), BERT (for natural language processing). On the other hand, you can generate synthetic data to increase labeled data. albumentations and imgaug help to generate data for an image while nlpaug generate textual data.
缺乏標簽數據是從業人員通常應對的挑戰之一。 遷移學習是克服它的方法之一。 您可以考慮使用ResNet(用于計算機視覺),BERT(用于自然語言處理)。 另一方面,您可以生成合成數據以增加標記數據。 albumentations和imgaug幫助,而生成的圖像數據nlpaug生成文本數據。
If you understand your data, you should tailor made augmentation approach it. Remember that the golden rule in data science is garbage in garbage out.
如果您了解自己的數據,則應量身定制增強方法。 請記住,數據科學中的黃金法則是將垃圾逐出。
采樣相同數據 (Sampling Same Data)
Photo by Jeremy Bishop on Unsplash 杰里米·畢曉普 ( Jeremy Bishop)在Unsplash上拍攝的照片Most of the time, we want to draw data randomly in order to keep the sample data distribution across a train set, test set, and validation set. Meanwhile, you want to keep this “random” behavior all the time such that you can get the same set of a train set, test set, and validation set.
大多數時候,我們希望隨機繪制數據,以保持樣本數據在訓練集,測試集和驗證集中的分布。 同時,您希望一直保持這種“隨機”行為,以便可以得到同一組訓練集,測試集和驗證集。
- If data come with a date attribute, you can split data by this column easily. 如果數據帶有日期屬性,則可以按此列輕松拆分數據。
- Otherwise, you can change the seed such that you can have consistent random behavior. 否則,您可以更改種子,以便具有一致的隨機行為。
import numpy as np
import randomseed = 1234
random.seed(seed)
np.random.seed(seed)
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
模型訓練 (Model Training)
保存中間檢查點 (Saving Intermediate Checkpoint)
Regrading to saving a trained model, one of the easier ways is saving it after completing the entire training process. However, there are several drawbacks. Let go through it together.
降級為保存訓練有素的模型,一種簡單的方法是在完成整個訓練過程后進行保存。 但是,有幾個缺點。 讓我們一起經歷一下。
Due to model complexity, computing resource, and size of training data, the entire model training process may take several days or weeks. It will be too risky if no intermediate checkpoints are persisted as a machine can be shutdown incidentally.
由于模型的復雜性,計算資源和訓練數據的大小 ,整個模型訓練過程可能需要幾天或幾周的時間。 如果不保留任何中間檢查點,則可能會太危險,因為機器可能會意外關閉。
In general, longer training model leads a better result (e.g., less loss). However, overfitting can happen. The last checkpoint does not deliver the best result in most of the time. We need to use an intermediate checkpoint for production most of the time.
通常,更長的訓練模型會帶來更好的結果(例如,更少的損失)。 但是,過度擬合可能會發生。 在大多數情況下,最后一個檢查點無法提供最佳結果 。 大多數時候,我們需要使用中間檢查點進行生產。
Saving your money when using an early stop mechanism. Noticed that a model does not improve for several around of epoch, we may stop it earlier to save time and resources. You may argue that the best model may be trained after several epochs. It is how you balance it.
使用提前停止機制可以省錢 。 請注意,某個模型在幾個時期內并沒有改善,我們可能會更早停止以節省時間和資源。 您可能會爭辯說,最好的模型可能會在幾個時期后得到訓練。 這就是平衡的方式。
So can we do it? Ideally, you may persist all checkpoints (e.g., saving model after every epoch), but it requests lots of storage. Indeed, it will be recommended to keep only the best model (or best three models) and the last model.
那我們能做到嗎? 理想情況下,您可以保留所有檢查點(例如,在每個時期之后保存模型),但是它需要大量存儲空間。 實際上,建議僅保留最佳模型(或最佳三個模型)和最后一個模型。
虛擬時代 (Virtual Epoch)
Epoch is a very common parameter in model training. It may affect your model performance if it does not initial correctly.
時代是模型訓練中非常普遍的參數。 如果初始化不正確,可能會影響模型性能。
For instance, if we have 1 million records and we set 5 epochs for training, there are 5 million (1M *5) training data in total. After three weeks, we got another 0.5 million records. If we use the same epoch (i.e., 5) for model training, total training data become 7.5 million (1.5M *5). The issues are :
例如,如果我們有100萬條記錄,并且設置了5個訓練紀元,則總共有500萬個(1M * 5)訓練數據。 三周后,我們又獲得了50萬條記錄。 如果我們使用相同的紀元(即5)進行模型訓練,則總訓練數據將達到750萬(1.5M * 5)。 問題是:
- It may not be easier to know the improvement of the model is caused by increasing unique training data or increasing total training data. 可能不容易知道模型的改進是由增加唯一訓練數據或增加總訓練數據引起的。
- Newly 0.5M extends training time to an hour or even days. It increases the risk of machine failure. 新近的0.5M將訓練時間延長到一個小時甚至幾天。 它增加了機器故障的風險。
Instead of using a static epoch, a virtual epoch is suggested to replace the original epoch. The virtual epoch can be calculated based on the size of training data, desired epoch, batch size.
建議使用虛擬紀元代替原始紀元,而不是使用靜態紀元。 虛擬紀元可以基于訓練數據的大小,期望紀元,批處理大小來計算。
Here is our usual setup:
這是我們通常的設置:
#originalnum_data = 1000 * 1000
batch_size = 100
num_step = 14 * 1000 * 1000
num_checkpoint = 20
steps_per_epoch = num_step//num_checkpoint#TensorFlow/ Keras
model.fit(x, epoch=num_checkpoint, steps_per_epoch=steps_per_epoch,
batch_size=batch_size
)
Indeed, you can use the following setup:
實際上,您可以使用以下設置:
num_data = 1000 * 1000num_total_data = 14 * 1000 * 1000
batch_size = 100
num_checkpoint = 20
steps_per_epoch = num_total_data // (batch_size*num_checkpoint)#TensorFlow/ Keras
model.fit(x, epoch=num_checkpoint, steps_per_epoch=steps_per_epoch,
batch_size=batch_size
)
簡單就是美 (Simple is Beauty)
Photo by LUM3N on Unsplash LUM3N在Unsplash上拍攝的照片Practitioners intend to use state-of-the-art models to build an initial model. Indeed, building a simple enough model as a baseline model is always recommended. Reasons are:
從業者打算使用最先進的模型來構建初始模型。 實際上,始終建議構建一個足夠簡單的模型作為基準模型。 原因如下:
We always need a baseline model to justify the proposed model. It is hard to tell a client that our amazing deep neural network model is better than others.
我們總是需要一個基線模型來證明所提議的模型的合理性。 很難告訴客戶我們驚人的深度神經網絡模型比其他模型更好。
The baseline model does not need to very good in terms of performance, but it must be explainable. A business user always wants to know the reasons for the prediction result.
基準模型在性能方面不需要非常好,但是必須可以解釋 。 商業用戶總是想知道預測結果的原因。
Easy to implement is very important. A client cannot wait for a year in order to get a good enough model. We need to build a set of models in order to gain momentum from an investor to build your wonderful model on top of the initial model.
易于實施非常重要。 客戶無法等待一年才能獲得足夠好的模型。 我們需要構建一組模型,以便從投資者那里獲得動力,以便在初始模型的基礎上構建出色的模型。
Here is some suggested baseline model in different fields:
這是不同領域的一些建議基準模型:
Acoustic: Instead of training a model to get a vector representation (i.e., embeddings layer), you may use classic features such as mel frequency cepstral coefficient (MFCC) or mel spectrogram features. Passing those features to a single layer of long short-term memory (LSTM) or convolutional neural network (CNN) and a fully connected layer for classification or prediction.
聲學 :您可以使用經典功能(例如梅爾頻率倒譜系數(MFCC)或梅爾頻譜圖功能)來代替訓練模型來獲取矢量表示(即,嵌入層)。 將這些特征傳遞到長短期記憶(LSTM)或卷積神經網絡(CNN)的單層以及用于分類或預測的完全連接的層。
Computer Vision (CV): TODO
計算機視覺 (CV):TODO
Natural Language Processing (NLP): Use bag-of-words or classic word embeddings with LSTM is a good starting point and shifting to transformer-based models such as BERT or XLNet later.
自然語言處理(NLP) :將單詞袋或經典單詞嵌入與LSTM一起使用是一個很好的起點,稍后再轉向基于轉換器的模型,例如BERT或XLNet 。
調試 (Debugging)
簡化問題 (Simplifying Problem)
Sometimes, classification problems include 1 million data with 1000 categories. It is too hard to debug your model when the model performance is lower than your exception. Bad performance can be contributed by model complexity, data quality, or bug. Therefore, it is recommended to simplify the problem such that we can guarantee it is bug-free. We leverage the overfitting problem to achieve this target.
有時,分類問題包括100萬個數據和1000個類別。 當模型性能低于異常時,很難調試模型。 模型復雜性,數據質量或錯誤可能導致性能不佳。 因此,建議簡化問題,以便我們可以保證它沒有錯誤。 我們利用過度擬合 問題來實現此目標。
Instead of classifying 1000 categories, you can sample 10 categories with 100 records per category and train your model. By using the same set (or subset) of training data as an evaluation dataset, you should able to overfit your model and achieving good results (e.g., 80 or even 90+ accuracy). If not, there may be some bugs in your model development.
無需對1000個類別進行分類,而是可以對10個類別進行采樣,每個類別100條記錄,并訓練模型。 通過使用相同的訓練數據集(或子集)作為評估數據集,您應該能夠過度擬合模型并獲得良好的結果 (例如,精度達到 80甚至90+)。 如果沒有,那么您的模型開發中可能會有一些錯誤。
使用評估模式進行訓練 (Using Eval Mode for Training)
If evaluation set accuracy does not change in the first several epoch, you may forget to reset “train” mode after evaluation
如果評估設置的準確性在前幾個時期沒有變化,您可能會忘記在評估后重置“訓練”模式
In PyTorch, you need to swap train and eval mode during training and evaluation. If train mode is enabled, batch normalization, dropout, or other layers will be affected. Sometimes, you may forget to enable it after evaluation.
在PyTorch中 ,您需要在訓練和評估期間交換train和eval模式。 如果啟用了訓練模式,則批量標準化,退出或其他層將受到影響。 有時,您可能會忘記在評估后啟用它。
model = MyModel() # Default mode is training modefor e in range(epoch):# mode.train() # forget to enable train mode
logits = model(x_train)
loss = loss_func(logits, y_train)
model.zero_grad()
loss.backward()
optimizer.step()mode.eval() # enable eval mode
with torch.no_grad():
eval_preds = model(x_val)
數據轉移 (Data Shifting)
Data shifting happened when the training dataset is different from the evaluation/ testing dataset. In the computer vision (CV) task, it may be possible that most of your training data are day time pictures while testing data are night time pictures.
當訓練數據集與評估/測試數據集不同時發生數據移位。 在計算機視覺(CV)任務中,您的大多數訓練數據可能是白天的圖片,而測試數據是夜間的圖片。
source)來源 )You may randomly pick some samples from both datasets for checking if you find that there is a big difference between training loss/ accuracy and test loss/ accuracy. To address this problem, you may consider:
如果您發現訓練損失/準確度與測試損失/準確度之間存在很大差異,則可以從兩個數據集中隨機抽取一些樣本進行檢查。 要解決此問題,您可以考慮:
Make sure that maintaining the similar distribution of data between training, test, and online prediction dataset.
確保在訓練,測試和在線預測數據集之間保持相似的數據分布 。
Add more training data if possible.
如果可能,添加更多的訓練數據 。
Add synthetic data by leveraging libraries. Consider using nlpaug (for natural language processing and acoustic task) and imgaug (for computer vision task).
利用庫添加綜合數據 。 考慮使用nlpaug (用于自然語言處理和聲學任務)和imgaug (用于計算機視覺任務)。
解決擬合不足 (Addressing Underfitting)
Underfitting means the training error is larger than the expected error. In other words, the model cannot achieve the expected performance. There are lots of factors causing a large error. To address this problem, you can start with an easier way to see whether it can be resolved. If this problem can be fixed in an earlier stage, you can save more time as easier it is in terms of less human effort.
欠擬合意味著訓練誤差大于預期誤差。 換句話說,該模型無法達到預期的性能。 有很多因素會導致較大的錯誤。 要解決此問題,您可以從一種更簡單的方法開始,看它是否可以解決。 如果可以在較早的階段解決此問題,則可以節省更多時間,因為這樣做可以減少人工工作量。
Perform error analysis. Interpreting your model via LIME, SHAP, or Anchor such that you can have a sense of the problem.
執行錯誤分析。 通過LIME , SHAP或Anchor 解釋模型 ,以便您可以了解問題所在。
An initial model may be too simple. Increase model complexity such as adding long short-term memory (LSTM) layers, convolution neural network (CNN) layers, or fully connected (FC) layers.
初始模型可能太簡單了。 增加模型的復雜性,例如增加長短期記憶(LSTM)層,卷積神經網絡(CNN)層或完全連接(FC)層。
Overfit model a little bit by reducing regularization layers. Dropout and weight decay are designed to prevent overfitting. You may try removing those regularization layouts to see whether a problem can be resolved.
通過減少正則化層,可以有點過擬合模型。 跌落和重量衰減旨在防止過度擬合。 您可以嘗試刪除那些正則化布局,以查看問題是否可以解決。
Adopt state-of-the-art model architecture. Considering using transformers (e.g., BERT or XLNet) in natural language processing (NLP)).
采用最先進的模型架構。 考慮在自然語言處理(NLP)中使用轉換器(例如BERT或XLNet )。
Introduce synthetic data. Generating more data helps with improving model performance without any human effort. Theoretically, generated data should share the same label. It allows the model to “see” more diverse data and improving robustness eventually. You can leverage nlpaug (for natural language processing and acoustic task) and imgaug (for computer vision task) to perform data augmentation.
介紹綜合數據 。 生成更多數據有助于無需任何人工就能提高模型性能。 從理論上講,生成的數據應該共享相同的標簽。 它允許模型“查看”更多不同的數據并最終提高魯棒性。 您可以利用nlpaug (用于自然語言處理和聲學任務)和imgaug (用于計算機視覺任務)執行數據增強 。
Assign better hyper-parameters and optimizer. Instead of using the default/ general learning rate, epoch, batch size, you may consider performing hyper-parameters tuning. Consider using beam search, grid search, or random search to identify a better hyper-parameters and optimizer. This approach is relatively simple by just changing hyper-parameters, but it may take a longer time.
分配更好的超參數和優化器。 您可以考慮執行超參數調整,而不是使用默認/常規學習率,時期,批處理大小。 考慮使用波束搜索,網格搜索或隨機搜索來確定更好的超參數和優化器 。 僅更改超參數,此方法相對簡單,但可能需要更長的時間。
解決過度擬合 (Addressing Overfitting)
Besides underfitting, you may also face the overfitting problems. Overfitting means that your model fits your training too much and not generalize enough for other data. In other words, your train loss/ accuracy is better than validation loss/ accuracy. Considering the following approaches to address it
除了擬合不足之外,您可能還會面臨擬合過度的問題。 過度擬合意味著您的模型過于適合您的訓練,而對于其他數據的概括不足。 換句話說,您的火車損失/準確性要比驗證損失/準確性好。 考慮以下解決方法
Perform error analysis. Interpreting your model via LIME, SHAP, or Anchor such that you can have a sense of the problem.
執行錯誤分析。 通過LIME , SHAP或Anchor 解釋模型 ,以便您可以了解問題所在。
Introduce regularization and normalization layers. Dropout (regularization layer) and batch normalization (normalization layer) help to reduce overfitting by removing some inputs and smoothing inputs.
介紹 正則化和歸一化層 。 輟學(正則化層)和批處理歸一化(歸一化層)通過刪除一些輸入并平滑輸入來幫助減少過度擬合。
Introduce synthetic data. Generating more data helps with improving model performance without any human effort. Theoretically, generated data should share the same label. It allows the model to “see” more diverse data and improving robustness eventually. You can leverage nlpaug (for natural language processing and acoustic task) and imaug (for computer vision task) to perform data augmentation.
介紹綜合數據 。 生成更多數據有助于無需任何人工就能提高模型性能。 從理論上講,生成的數據應該共享相同的標簽。 它允許模型“查看”更多不同的數據并最終提高魯棒性。 您可以利用nlpaug (用于自然語言處理和聲學任務)和imaug (用于計算機視覺任務)執行數據增強 。
Assign better hyper-parameters and optimizer. Instead of using the default/ general learning rate, epoch, batch size, you may consider performing hyper-parameters tuning. Consider using beam search, grid search, or random search to identify a better hyper-parameters and optimizer. This approach is relatively simple by just changing hyper-parameters, but it may take a longer time.
分配更好的超參數和優化器。 您可以考慮執行超參數調整,而不是使用默認/常規學習率,時期,批處理大小。 考慮使用波束搜索,網格搜索或隨機搜索來確定更好的超參數和優化器 。 僅更改超參數,此方法相對簡單,但可能需要更長的時間。
Remove features.
刪除功能 。
A model may be too complex. Decrease model complexity.
模型可能太復雜。 降低 模型復雜度 。
生產 (Production)
元數據協會 (Meta Data Association)
After your model is rollout, you need to check out some exceptional cases. One way to do it is by generating ID and persisting it to the database. However, it comes with several issues that increase the difficulty of troubleshooting. Here are some disadvantages:
展開模型后,您需要檢查一些例外情況。 一種方法是通過生成ID并將其持久化到數據庫中。 但是,它帶有幾個問題,增加了故障排除的難度。 這里有一些缺點:
The coupling problem impacts system flexibility. In architecture design point of view, decoupling is one of way to build a high flexibility system. If we generate ID and passing prediction results with this ID to a client, the client needs to persist it in their database. What if we changed format or data type, you need to inform all consumer to update their database scheme.
耦合問題影響系統的靈活性。 從體系結構設計的角度來看, 去耦是構建高靈活性系統的一種方法 。 如果我們生成ID并將具有該ID的預測結果傳遞給客戶端,則客戶端需要將其持久化在他們的數據庫中。 如果我們更改了格式或數據類型,您需要通知所有使用者更新其數據庫方案該怎么辦。
We may need to gather more metadata based on the consumer’s primary key. Extra primary key increases joining complexity and storage consumption. Instead.
我們可能需要根據使用者的主鍵收集更多的元數據。 額外的主鍵增加了連接的復雜性和存儲消耗 。 代替。
To overcome this problem, the prediction result should associate with the consumer’s primary key directly.
為了克服這個問題,預測結果應直接與消費者的主鍵關聯。
切換到推理模式 (Switch to Inference Mode)
When using PyTorch, there are several settings that you should take care when deploying your model to production. Aforementioned about eval in PyTorch, it makes those layers (e.g., Dropout, BatchNorm) work in inference mode such as no dropout action is applied in inference time. It does not only speeds up your process but also feeding all information to the neural network. detach and torch.no_grad will help you to get a result from a graph and using less memory.
使用PyTorch時,在將模型部署到生產環境時,應注意一些設置。 上述關于eval在PyTorch,它使那些層(例如,差,BatchNorm)在推理模式工作,例如沒有下降現象動作在推理時施加。 它不僅可以加快您的處理速度,而且可以將所有信息饋送到神經網絡。 detach和torch.no_grad將幫助您從圖形中獲得結果并使用較少的內存。
mode.eval() # enable eval modewith torch.no_grad():
eval_preds = model(x_val)
縮放成本 (Scaling Cost)
When you try to scaling out API to handle more throughput, you may consider using GPU sometimes. It is true that the GPU VM is much more expensive than the CPU. However, GPU brings some advantages to you, such as less computation time, and less VM is required to maintain the same service level. Try to evaluate and see whether GPU saves some money.
當您嘗試擴展API以處理更大的吞吐量時,您可能會考慮有時使用GPU。 確實,GPU VM比CPU貴得多。 但是,GPU為您帶來了一些優勢,例如更少的計算時間,以及需要更少的VM來維持相同的服務水平。 嘗試評估一下,看看GPU是否可以節省一些錢。
無狀態 (Stateless)
Try to make your API stateless such that your API service can be scaled easily. Stateless means do NOT save any intermediate result in an API server (memory or local storage). Just keep the API server simple and returning the result to the client without storing anything in memory or local storage.
嘗試使您的API變為無狀態,以便可以輕松擴展您的API服務。 無狀態意味著不要將任何中間結果保存在API服務器(內存或本地存儲)中。 只需保持API服務器簡單,然后將結果返回給客戶端,而無需在內存或本地存儲中存儲任何內容。
批處理 (Batch Process)
Predicting a set of records usually faster than record one by one. Most of the modern machine learning or deep learning framework optimized prediction performance (in terms of speed). You may notice there are great improvements by switching to batch mode prediction.
預測一組記錄通常比一個記錄更快。 大多數現代機器學習或深度學習框架都優化了預測性能(在速度方面)。 您可能會注意到,切換到批處理模式預測有很大的改進。
使用C ++ (Use C++)
Although Python is the first-class citizen in the machine learning field, it may too slow when compared to other programming languages such as C++. You may consider using TorchScript if you desire low latency inference time. The general idea is you can still train your model in Python and generate C++ compatible model by using it.
盡管Python是機器學習領域的一等公民,但與其他編程語言(例如C ++)相比,它可能會太慢。 如果您希望低延遲推理時間,則可以考慮使用TorchScript 。 通常的想法是,您仍然可以使用Python訓練模型并使用它生成C ++兼容模型。
翻譯自: https://medium.com/towards-artificial-intelligence/tricks-of-building-an-ml-or-dnn-model-b2de54cf440a
lr模型和dnn模型
總結
以上是生活随笔為你收集整理的lr模型和dnn模型_建立ML或DNN模型的技巧的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一文读懂安检机器的工作原理
- 下一篇: 超预期目标1000倍!《流浪地球2》周边