Phát hiện dữ liệu bất thường trong TensorFlow và Keras bằng phương pháp Autoencoder | của Rashida Nasrin Sucky

Rashida Nasrin Sucky

#AnomalyDetection #TensorFlow #Keras #Autoencoder #MachineLearning #UnsupervisedLearning

Hôm nay chúng ta sẽ tìm hiểu về phương pháp phát hiện dạng bất thường trong TensorFlow và Keras sử dụng phương pháp Autoencoder. Trước đây, tất cả các hướng dẫn về TensorFlow và mạng neural mà tôi đã chia sẻ đều liên quan đến việc học có giám sát. Lần này, chúng ta sẽ tìm hiểu về Autoencoder, một phương pháp học không có giám sát.

Để diễn tả một cách đơn giản, autoencoder giảm thiểu các nhiễu từ dữ liệu bằng cách nén dữ liệu đầu vào, mã hóa và tái tạo dữ liệu. Điều này giúp autoencoder giảm chiều dữ liệu hoặc nhiễu và tập trung vào trọng tâm thực sự của dữ liệu đầu vào.

Như bạn có thể thấy từ giới thiệu về autoencoder ở đây, có nhiều quy trình cần được thực hiện. Trước tiên, một mô hình để nén dữ liệu đầu vào, đó là mô hình mã hóa. Sau đó là một mô hình khác để tái tạo dữ liệu đã nén sao cho gần giống với dữ liệu đầu vào, đó là mô hình giải mã. Qua quá trình này, autoencoder có thể loại bỏ nhiễu, giảm chiều dữ liệu và làm sạch dữ liệu đầu vào.

Trong hướng dẫn này, tôi sẽ giải thích chi tiết cách autoencoder hoạt động thông qua một ví dụ thực tế. Với ví dụ này, tôi đã chọn sử dụng một tập dữ liệu công cộng (Apache License 2.0) có tên là deep_weeds.

Để chuẩn bị cho ví dụ phát hiện dạng bất thường không giám sát này, chúng ta cần chuẩn bị một tập dữ liệu. Chỉ có một lớp sẽ được chọn là lớp chính được coi là lớp hợp lệ. Và tôi sẽ sử dụng một số dữ liệu từ một lớp khác làm dạng bất thường. Sau đó, chúng ta sẽ phát triển mô hình để xem liệu chúng ta có thể tìm ra được những dữ liệu bất thường đó.

Trong đoạn mã dưới đây, tôi lấy tất cả dữ liệu của các lớp 5 và 1 trước tiên và tạo các danh sách các hình ảnh và nhãn tương ứng của chúng.

import tensorflow as tf
import tensorflow_datasets as tfds

ds = tfds.load(‘deep_weeds’, split=”train”, shuffle_files=True)

# Chuẩn bị dữ liệu
images_main = [] images_anomaly = [] labels_main = [] labels_anomaly = []

ds = ds.prefetch(tf.data.AUTOTUNE)
for example in ds:

Nguồn: [Link bài viết](source link)

Nguồn: https://techtoday.co/anomaly-detection-in-tensorflow-and-keras-using-the-autoencoder-method-by-rashida-nasrin-sucky-sep-2023/

Photo by Leiada Krozjhen on Unsplash

A cutting-edge unsupervised method for noise removal, dimensionality reduction, anomaly detection, and more

Rashida Nasrin Sucky

All the tutorials about TensorFlow and neural networks I have shared until now have been about supervised learning. This one will be about the Autoenocder which is an unsupervised learning technique. If I want to express it simply, autoencoders reduce the noises from the data by compressing the input data, and encoding and reconstructing the data. That way autoencoders can reduce the dimensionality or the noise of the data and focus on the real focal point of the input data.

As you can see from the introduction to the autoencoders here there is more than one process required.

  1. First, a model to compress the input data which is the encoder model.
  2. Then another model to reconstruct the compressed data that should be as close as the input data which is a decoder model.

In this process, it can remove the noise, reduce the dimensionality, and clear up the input data.

In this tutorial, I will explain in detail how an autoencoder works with a working example.

For this example, I chose to use a public dataset (Apache License 2.0) named deep_weeds.

import tensorflow as tf
import tensorflow_datasets as tfds
ds = tfds.load('deep_weeds', split="train", shuffle_files=True)

Data Preparation

We need to prepare a dataset for this unsupervised anomaly detection example. Only one class will be taken as our main class that will be considered as the valid class. And I will put a few data from another class as an anomaly. Then we will develop the model to see if we can find that few anomaly data.

I chose class 5 as the valid class and class 1 as the anomaly. In the code block below, I am taking all the data of classes 5 and 1 first and creating lists of the images and their corresponding labels.

import numpy as np
images_main = ()
images_anomaly = ()
labels_main= ()
labels_anomaly = ()
ds = ds.prefetch(tf.data.AUTOTUNE)
for example in ds…

Source link


[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *