Một ví dụ về thế giới vật chất sẽ là đặt hai gương song song đối diện nhau. Bất kỳ đối tượng nào ở giữa chúng sẽ được phản ánh đệ quy
Hàm đệ quy PythonTrong Python, chúng ta biết rằng một hàm có thể gọi các hàm khác. Hàm thậm chí có thể gọi chính nó. Các loại cấu trúc này được gọi là hàm đệ quy Hình ảnh sau đây cho thấy hoạt động của một hàm đệ quy có tên là # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
5Hàm đệ quy trong PythonSau đây là một ví dụ về hàm đệ quy để tìm giai thừa của một số nguyên Giai thừa của một số là tích của tất cả các số nguyên từ 1 đến số đó. Ví dụ, giai thừa của 6 (ký hiệu là 6. ) là 1*2*3*4*5*6 = 720 Ví dụ về hàm đệ quydef factorial(x):
"""This is a recursive function
to find the factorial of an integer"""
if x == 1:
return 1
else:
return (x * factorial(x-1))
num = 3
print("The factorial of", num, "is", factorial(num))
đầu ra The factorial of 3 is 6 Trong ví dụ trên, # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
6 là một hàm đệ quy vì nó gọi chính nóKhi ta gọi hàm này với số nguyên dương thì nó sẽ gọi đệ quy chính nó bằng cách giảm số Mỗi hàm nhân một số với giai thừa của số bên dưới nó cho đến khi nó bằng một. Cuộc gọi đệ quy này có thể được giải thích trong các bước sau factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call Hãy xem một hình ảnh thể hiện quy trình từng bước về những gì đang diễn ra Làm việc của hàm giai thừa đệ quyĐệ quy của chúng tôi kết thúc khi số lượng giảm xuống 1. Đây được gọi là điều kiện cơ sở Mỗi hàm đệ quy phải có một điều kiện cơ bản để dừng đệ quy, nếu không thì hàm sẽ tự gọi nó vô hạn Trình thông dịch Python giới hạn độ sâu của đệ quy để giúp tránh các đệ quy vô hạn, dẫn đến tràn ngăn xếp Theo mặc định, độ sâu đệ quy tối đa là 1000. Nếu giới hạn bị vượt qua, kết quả là # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
7. Hãy xem xét một điều kiện như vậy Xem các phiên từ Hội nghị chuyên đề WiML về các mô hình khuếch tán với KerasCV, ML trên thiết bị, v.v. Xem theo yêu cầu - TenorFlow
- Học hỏi
- Lõi TensorFlow
- Hướng dẫn
Viết vòng lặp đào tạo từ đầu Sắp xếp ngăn nắp với các bộ sưu tập Lưu và phân loại nội dung dựa trên sở thích của bạn. Xem trên TensorFlow. orgChạy trong Google ColabXem nguồn trên GitHubTải xuống sổ ghi chépCài đặtimport tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
Giới thiệuKeras cung cấp các vòng đào tạo và đánh giá mặc định, # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
2 và # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
3. Việc sử dụng chúng được trình bày trong hướng dẫn Đào tạo & đánh giá với các phương pháp tích hợpNếu bạn muốn tùy chỉnh thuật toán học tập của mô hình của mình trong khi vẫn tận dụng sự tiện lợi của # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
2 (ví dụ: để đào tạo GAN bằng cách sử dụng # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
2), bạn có thể phân lớp lớp # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
6 và triển khai phương thức # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
7 của riêng bạn, phương thức này được gọi lặp đi lặp lại trong thời gian # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
2. Điều này được đề cập trong hướng dẫn Tùy chỉnh những gì diễn ra trong # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
2Bây giờ, nếu bạn muốn kiểm soát ở mức rất thấp đối với đào tạo và đánh giá, bạn nên viết các vòng đào tạo và đánh giá của riêng mình từ đầu. Đây là những gì hướng dẫn này là về Sử dụng The factorial of 3 is 620. một ví dụ end-to-end đầu tiênGọi một mô hình bên trong phạm vi The factorial of 3 is 6 20 cho phép bạn truy xuất độ dốc của các trọng số có thể huấn luyện của lớp đối với giá trị mất mát. Sử dụng một phiên bản trình tối ưu hóa, bạn có thể sử dụng các gradient này để cập nhật các biến này (bạn có thể truy xuất các biến này bằng cách sử dụng The factorial of 3 is 6 22)Hãy xem xét một mô hình MNIST đơn giản The factorial of 3 is 6 5Hãy huấn luyện nó bằng cách sử dụng gradient lô nhỏ với vòng huấn luyện tùy chỉnh Đầu tiên, chúng ta sẽ cần một trình tối ưu hóa, hàm mất mát và tập dữ liệu # Instantiate an optimizer.
optimizer = keras.optimizers.SGD(learning_rate=1e-3)
# Instantiate a loss function.
loss_fn = keras.losses.SparseCategoricalCrossentropy(from_logits=True)
# Prepare the training dataset.
batch_size = 64
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
x_train = np.reshape(x_train, (-1, 784))
x_test = np.reshape(x_test, (-1, 784))
# Reserve 10,000 samples for validation.
x_val = x_train[-10000:]
y_val = y_train[-10000:]
x_train = x_train[:-10000]
y_train = y_train[:-10000]
# Prepare the training dataset.
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
train_dataset = train_dataset.shuffle(buffer_size=1024).batch(batch_size)
# Prepare the validation dataset.
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val))
val_dataset = val_dataset.batch(batch_size)
The factorial of 3 is 6 2Đây là vòng lặp đào tạo của chúng tôi - Chúng tôi mở một vòng lặp
The factorial of 3 is 6 23 lặp lại qua các kỷ nguyên - Đối với mỗi kỷ nguyên, chúng tôi mở một vòng lặp
The factorial of 3 is 6 23 lặp lại trên tập dữ liệu theo đợt - Đối với mỗi đợt, chúng tôi mở một phạm vi
The factorial of 3 is 6 25 - Trong phạm vi này, chúng tôi gọi mô hình (chuyển tiếp) và tính toán tổn thất
- Bên ngoài phạm vi, chúng tôi truy xuất độ dốc của trọng số của mô hình liên quan đến sự mất mát
- Cuối cùng, chúng tôi sử dụng trình tối ưu hóa để cập nhật trọng số của mô hình dựa trên độ dốc
factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call 1factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call 2Xử lý số liệu ở mức độ thấpHãy thêm giám sát số liệu vào vòng lặp cơ bản này Bạn có thể dễ dàng sử dụng lại các chỉ số tích hợp sẵn (hoặc các chỉ số tùy chỉnh mà bạn đã viết) trong các vòng đào tạo được viết từ đầu như vậy. Đây là dòng chảy - Khởi tạo số liệu khi bắt đầu vòng lặp
- Gọi
The factorial of 3 is 6 26 sau mỗi đợt - Gọi
The factorial of 3 is 6 27 khi bạn cần hiển thị giá trị hiện tại của số liệu - Gọi
The factorial of 3 is 6 28 khi bạn cần xóa trạng thái của số liệu (thường là vào cuối một kỷ nguyên)
Hãy sử dụng kiến thức này để tính toán The factorial of 3 is 6 29 trên dữ liệu xác thực ở cuối mỗi kỷ nguyênfactorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call 7Đây là vòng lặp đào tạo và đánh giá của chúng tôi factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call 8factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call 9Tăng tốc bước đào tạo của bạn với factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call10Thời gian chạy mặc định trong TensorFlow 2 là thực thi háo hức. Như vậy, vòng lặp đào tạo của chúng tôi ở trên thực hiện một cách háo hức Điều này rất tốt cho việc gỡ lỗi, nhưng việc biên dịch biểu đồ có một lợi thế về hiệu suất nhất định. Mô tả tính toán của bạn dưới dạng biểu đồ tĩnh cho phép khung áp dụng tối ưu hóa hiệu suất toàn cầu. Điều này là không thể khi khung bị hạn chế tham lam thực hiện hết thao tác này đến thao tác khác mà không biết điều gì sẽ xảy ra tiếp theo Bạn có thể biên dịch thành một biểu đồ tĩnh bất kỳ chức năng nào lấy tenxơ làm đầu vào. Chỉ cần thêm một trang trí factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call 11 vào nó, như thế nàyimport tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
import numpy as np
2Hãy làm tương tự với bước đánh giá The factorial of 3 is 6 50Bây giờ, hãy chạy lại vòng lặp đào tạo của chúng ta với bước đào tạo đã biên soạn này The factorial of 3 is 6 51The factorial of 3 is 6 52Nhanh hơn nhiều, phải không? Xử lý tổn thất ở mức độ thấp được theo dõi bởi mô hìnhCác lớp và mô hình theo dõi đệ quy bất kỳ tổn thất nào được tạo ra trong quá trình chuyển tiếp bởi các lớp gọi là ________ 212. Danh sách kết quả của các giá trị tổn thất vô hướng có sẵn thông qua thuộc tính factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call 13 ở cuối quá trình chuyển tiếpNếu bạn muốn sử dụng các thành phần tổn thất này, bạn nên tính tổng và cộng chúng vào tổn thất chính trong bước đào tạo của mình Hãy xem xét lớp này, điều đó tạo ra sự mất mát chính quy hóa hoạt động The factorial of 3 is 6 53Hãy xây dựng một mô hình thực sự đơn giản sử dụng nó The factorial of 3 is 6 54Đây là bước đào tạo của chúng ta sẽ như thế nào bây giờ The factorial of 3 is 6 55Tóm lượcBây giờ bạn đã biết mọi thứ cần biết về cách sử dụng vòng lặp đào tạo tích hợp sẵn và viết vòng lặp của riêng bạn từ đầu Để kết luận, đây là một ví dụ đầu cuối đơn giản liên kết mọi thứ bạn đã học được trong hướng dẫn này lại với nhau. một DCGAN được đào tạo trên các chữ số MNIST Ví dụ đầu cuối. một vòng đào tạo GAN từ đầuBạn có thể quen thuộc với Generative Adversarial Networks (GAN). GAN có thể tạo ra những hình ảnh mới trông gần như thật, bằng cách tìm hiểu phân phối tiềm ẩn của tập dữ liệu huấn luyện hình ảnh ("không gian tiềm ẩn" của hình ảnh) Một GAN được làm bằng hai phần. mô hình "trình tạo" ánh xạ các điểm trong không gian tiềm ẩn tới các điểm trong không gian hình ảnh, mô hình "phân biệt đối xử", một bộ phân loại có thể cho biết sự khác biệt giữa hình ảnh thực (từ tập dữ liệu huấn luyện) và hình ảnh giả (đầu ra của mạng trình tạo Một vòng đào tạo GAN trông như thế này 1) Huấn luyện người phân biệt đối xử. - Lấy mẫu một loạt các điểm ngẫu nhiên trong không gian tiềm ẩn. - Biến các điểm thành hình ảnh giả thông qua mô hình "máy phát điện". - Nhận một loạt hình ảnh thực và kết hợp chúng với các hình ảnh được tạo. - Huấn luyện mô hình "phân biệt đối xử" để phân loại được tạo ra so với. hình ảnh thật 2) Đào tạo máy phát điện. - Lấy mẫu các điểm ngẫu nhiên trong không gian tiềm ẩn. - Biến các điểm thành ảnh giả thông qua mạng "máy phát điện". - Nhận hàng loạt ảnh thật và kết hợp chúng với ảnh đã tạo. - Huấn luyện mô hình "máy phát điện" để "đánh lừa" bộ phân biệt và phân loại ảnh giả thành ảnh thật Để biết tổng quan chi tiết hơn về cách thức hoạt động của GAN, hãy xem Deep Learning với Python Hãy thực hiện vòng lặp đào tạo này. Đầu tiên, tạo bộ phân biệt để phân loại chữ số giả và chữ số thật The factorial of 3 is 6 56____157Sau đó, hãy tạo một mạng máy phát, biến các vectơ tiềm ẩn thành đầu ra có hình dạng factorial(3) # 1st call with 3
3 * factorial(2) # 2nd call with 2
3 * 2 * factorial(1) # 3rd call with 1
3 * 2 * 1 # return from 3rd call as number=1
3 * 2 # return from 2nd call
6 # return from 1st call 14 (đại diện cho các chữ số MNIST)The factorial of 3 is 6 58Đây là điểm mấu chốt. vòng lặp đào tạo. Như bạn có thể thấy nó khá đơn giản. Chức năng bước đào tạo chỉ mất 17 dòng |