diff --git a/lesson01-TF2.0-Overview/.gitignore b/01-TF2.0-Overview/.gitignore similarity index 100% rename from lesson01-TF2.0-Overview/.gitignore rename to 01-TF2.0-Overview/.gitignore diff --git a/lesson01-TF2.0-Overview/README.md b/01-TF2.0-Overview/README.md similarity index 100% rename from lesson01-TF2.0-Overview/README.md rename to 01-TF2.0-Overview/README.md diff --git a/lesson01-TF2.0-Overview/conv_train.py b/01-TF2.0-Overview/conv_train.py similarity index 99% rename from lesson01-TF2.0-Overview/conv_train.py rename to 01-TF2.0-Overview/conv_train.py index 64013cb..2cc153c 100644 --- a/lesson01-TF2.0-Overview/conv_train.py +++ b/01-TF2.0-Overview/conv_train.py @@ -1,12 +1,15 @@ import os import time import numpy as np +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # or any {'0', '1', '2'} + + import tensorflow as tf from tensorflow.python.ops import summary_ops_v2 from tensorflow import keras from tensorflow.keras import datasets, layers, models, optimizers, metrics -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' # or any {'0', '1', '2'} + model = tf.keras.Sequential([ diff --git a/lesson01-TF2.0-Overview/fc_train.py b/01-TF2.0-Overview/fc_train.py similarity index 100% rename from lesson01-TF2.0-Overview/fc_train.py rename to 01-TF2.0-Overview/fc_train.py diff --git a/lesson01-TF2.0-Overview/features.png b/01-TF2.0-Overview/features.png similarity index 100% rename from lesson01-TF2.0-Overview/features.png rename to 01-TF2.0-Overview/features.png diff --git a/lesson02-AutoGraph/README.md b/02-AutoGraph/README.md similarity index 100% rename from lesson02-AutoGraph/README.md rename to 02-AutoGraph/README.md diff --git a/lesson02-AutoGraph/graph.gif b/02-AutoGraph/graph.gif similarity index 100% rename from lesson02-AutoGraph/graph.gif rename to 02-AutoGraph/graph.gif diff --git a/lesson02-AutoGraph/main.py b/02-AutoGraph/main.py similarity index 100% rename from lesson02-AutoGraph/main.py rename to 02-AutoGraph/main.py diff --git a/lesson03-Play-with-MNIST/README.md b/03-Play-with-MNIST/README.md similarity index 100% rename from lesson03-Play-with-MNIST/README.md rename to 03-Play-with-MNIST/README.md diff --git a/lesson03-Play-with-MNIST/main.py b/03-Play-with-MNIST/main.py similarity index 100% rename from lesson03-Play-with-MNIST/main.py rename to 03-Play-with-MNIST/main.py diff --git a/lesson03-Play-with-MNIST/mnist.gif b/03-Play-with-MNIST/mnist.gif similarity index 100% rename from lesson03-Play-with-MNIST/mnist.gif rename to 03-Play-with-MNIST/mnist.gif diff --git a/lesson12-Linear-Regression/README.md b/04-Linear-Regression/README.md similarity index 100% rename from lesson12-Linear-Regression/README.md rename to 04-Linear-Regression/README.md diff --git a/lesson12-Linear-Regression/linear_regression.png b/04-Linear-Regression/linear_regression.png similarity index 100% rename from lesson12-Linear-Regression/linear_regression.png rename to 04-Linear-Regression/linear_regression.png diff --git a/lesson12-Linear-Regression/main.py b/04-Linear-Regression/main.py similarity index 100% rename from lesson12-Linear-Regression/main.py rename to 04-Linear-Regression/main.py diff --git a/lesson14-FashionMNIST/.gitignore b/05-FashionMNIST/.gitignore similarity index 100% rename from lesson14-FashionMNIST/.gitignore rename to 05-FashionMNIST/.gitignore diff --git a/lesson14-FashionMNIST/README.md b/05-FashionMNIST/README.md similarity index 100% rename from lesson14-FashionMNIST/README.md rename to 05-FashionMNIST/README.md diff --git a/lesson14-FashionMNIST/fashion_mnist.png b/05-FashionMNIST/fashion_mnist.png similarity index 100% rename from lesson14-FashionMNIST/fashion_mnist.png rename to 05-FashionMNIST/fashion_mnist.png diff --git a/lesson14-FashionMNIST/mnist_Seqential_gradient.py b/05-FashionMNIST/mnist_Seqential_gradient.py similarity index 100% rename from lesson14-FashionMNIST/mnist_Seqential_gradient.py rename to 05-FashionMNIST/mnist_Seqential_gradient.py diff --git a/lesson14-FashionMNIST/mnist_custommodel.py b/05-FashionMNIST/mnist_custommodel.py similarity index 100% rename from lesson14-FashionMNIST/mnist_custommodel.py rename to 05-FashionMNIST/mnist_custommodel.py diff --git a/lesson14-FashionMNIST/mnist_fit.py b/05-FashionMNIST/mnist_fit.py similarity index 100% rename from lesson14-FashionMNIST/mnist_fit.py rename to 05-FashionMNIST/mnist_fit.py diff --git a/lesson14-FashionMNIST/mnist_matmul.py b/05-FashionMNIST/mnist_matmul.py similarity index 100% rename from lesson14-FashionMNIST/mnist_matmul.py rename to 05-FashionMNIST/mnist_matmul.py diff --git a/lesson15-CIFAR-VGG/.gitignore b/06-CIFAR-VGG/.gitignore similarity index 100% rename from lesson15-CIFAR-VGG/.gitignore rename to 06-CIFAR-VGG/.gitignore diff --git a/lesson15-CIFAR-VGG/README.md b/06-CIFAR-VGG/README.md similarity index 100% rename from lesson15-CIFAR-VGG/README.md rename to 06-CIFAR-VGG/README.md diff --git a/lesson15-CIFAR-VGG/main.py b/06-CIFAR-VGG/main.py similarity index 100% rename from lesson15-CIFAR-VGG/main.py rename to 06-CIFAR-VGG/main.py diff --git a/lesson15-CIFAR-VGG/network.py b/06-CIFAR-VGG/network.py similarity index 100% rename from lesson15-CIFAR-VGG/network.py rename to 06-CIFAR-VGG/network.py diff --git a/lesson15-CIFAR-VGG/vgg16.png b/06-CIFAR-VGG/vgg16.png similarity index 100% rename from lesson15-CIFAR-VGG/vgg16.png rename to 06-CIFAR-VGG/vgg16.png diff --git a/lesson16-Inception/.gitignore b/07-Inception/.gitignore similarity index 100% rename from lesson16-Inception/.gitignore rename to 07-Inception/.gitignore diff --git a/lesson16-Inception/README.md b/07-Inception/README.md similarity index 100% rename from lesson16-Inception/README.md rename to 07-Inception/README.md diff --git a/lesson16-Inception/inception.png b/07-Inception/inception.png similarity index 100% rename from lesson16-Inception/inception.png rename to 07-Inception/inception.png diff --git a/lesson16-Inception/main.py b/07-Inception/main.py similarity index 100% rename from lesson16-Inception/main.py rename to 07-Inception/main.py diff --git a/lesson17-ResNet/.gitignore b/08-ResNet/.gitignore similarity index 100% rename from lesson17-ResNet/.gitignore rename to 08-ResNet/.gitignore diff --git a/lesson17-ResNet/README.md b/08-ResNet/README.md similarity index 100% rename from lesson17-ResNet/README.md rename to 08-ResNet/README.md diff --git a/lesson17-ResNet/main.py b/08-ResNet/main.py similarity index 100% rename from lesson17-ResNet/main.py rename to 08-ResNet/main.py diff --git a/lesson17-ResNet/resnet.jpeg b/08-ResNet/resnet.jpeg similarity index 100% rename from lesson17-ResNet/resnet.jpeg rename to 08-ResNet/resnet.jpeg diff --git a/lesson18-RNN-Sentiment-Analysis/.gitignore b/09-RNN-Sentiment-Analysis/.gitignore similarity index 100% rename from lesson18-RNN-Sentiment-Analysis/.gitignore rename to 09-RNN-Sentiment-Analysis/.gitignore diff --git a/lesson18-RNN-Sentiment-Analysis/README.md b/09-RNN-Sentiment-Analysis/README.md similarity index 100% rename from lesson18-RNN-Sentiment-Analysis/README.md rename to 09-RNN-Sentiment-Analysis/README.md diff --git a/lesson18-RNN-Sentiment-Analysis/imdb.png b/09-RNN-Sentiment-Analysis/imdb.png similarity index 100% rename from lesson18-RNN-Sentiment-Analysis/imdb.png rename to 09-RNN-Sentiment-Analysis/imdb.png diff --git a/lesson18-RNN-Sentiment-Analysis/main.py b/09-RNN-Sentiment-Analysis/main.py similarity index 100% rename from lesson18-RNN-Sentiment-Analysis/main.py rename to 09-RNN-Sentiment-Analysis/main.py diff --git a/lesson19-ColorBot/.gitignore b/10-ColorBot/.gitignore similarity index 100% rename from lesson19-ColorBot/.gitignore rename to 10-ColorBot/.gitignore diff --git a/lesson19-ColorBot/README.md b/10-ColorBot/README.md similarity index 100% rename from lesson19-ColorBot/README.md rename to 10-ColorBot/README.md diff --git a/lesson19-ColorBot/blue.png b/10-ColorBot/blue.png similarity index 100% rename from lesson19-ColorBot/blue.png rename to 10-ColorBot/blue.png diff --git a/lesson19-ColorBot/green.png b/10-ColorBot/green.png similarity index 100% rename from lesson19-ColorBot/green.png rename to 10-ColorBot/green.png diff --git a/lesson19-ColorBot/main.py b/10-ColorBot/main.py similarity index 100% rename from lesson19-ColorBot/main.py rename to 10-ColorBot/main.py diff --git a/lesson19-ColorBot/model.py b/10-ColorBot/model.py similarity index 100% rename from lesson19-ColorBot/model.py rename to 10-ColorBot/model.py diff --git a/lesson19-ColorBot/purple.png b/10-ColorBot/purple.png similarity index 100% rename from lesson19-ColorBot/purple.png rename to 10-ColorBot/purple.png diff --git a/lesson19-ColorBot/red.png b/10-ColorBot/red.png similarity index 100% rename from lesson19-ColorBot/red.png rename to 10-ColorBot/red.png diff --git a/lesson19-ColorBot/shot.png b/10-ColorBot/shot.png similarity index 100% rename from lesson19-ColorBot/shot.png rename to 10-ColorBot/shot.png diff --git a/lesson19-ColorBot/utils.py b/10-ColorBot/utils.py similarity index 100% rename from lesson19-ColorBot/utils.py rename to 10-ColorBot/utils.py diff --git a/lesson21-AE/README.md b/11-AE/README.md similarity index 100% rename from lesson21-AE/README.md rename to 11-AE/README.md diff --git a/lesson21-AE/autoencoder.png b/11-AE/autoencoder.png similarity index 100% rename from lesson21-AE/autoencoder.png rename to 11-AE/autoencoder.png diff --git a/lesson21-AE/images/vae_reconstructed_epoch_1.png b/11-AE/images/vae_reconstructed_epoch_1.png similarity index 100% rename from lesson21-AE/images/vae_reconstructed_epoch_1.png rename to 11-AE/images/vae_reconstructed_epoch_1.png diff --git a/lesson21-AE/images/vae_reconstructed_epoch_2.png b/11-AE/images/vae_reconstructed_epoch_2.png similarity index 100% rename from lesson21-AE/images/vae_reconstructed_epoch_2.png rename to 11-AE/images/vae_reconstructed_epoch_2.png diff --git a/lesson21-AE/images/vae_reconstructed_epoch_3.png b/11-AE/images/vae_reconstructed_epoch_3.png similarity index 100% rename from lesson21-AE/images/vae_reconstructed_epoch_3.png rename to 11-AE/images/vae_reconstructed_epoch_3.png diff --git a/lesson21-AE/images/vae_reconstructed_epoch_4.png b/11-AE/images/vae_reconstructed_epoch_4.png similarity index 100% rename from lesson21-AE/images/vae_reconstructed_epoch_4.png rename to 11-AE/images/vae_reconstructed_epoch_4.png diff --git a/lesson21-AE/images/vae_reconstructed_epoch_5.png b/11-AE/images/vae_reconstructed_epoch_5.png similarity index 100% rename from lesson21-AE/images/vae_reconstructed_epoch_5.png rename to 11-AE/images/vae_reconstructed_epoch_5.png diff --git a/lesson21-AE/main.py b/11-AE/main.py similarity index 100% rename from lesson21-AE/main.py rename to 11-AE/main.py diff --git a/lesson22-VAE/README.md b/12-VAE/README.md similarity index 100% rename from lesson22-VAE/README.md rename to 12-VAE/README.md diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_1.png b/12-VAE/images/vae_reconstructed_epoch_1.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_1.png rename to 12-VAE/images/vae_reconstructed_epoch_1.png diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_2.png b/12-VAE/images/vae_reconstructed_epoch_2.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_2.png rename to 12-VAE/images/vae_reconstructed_epoch_2.png diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_3.png b/12-VAE/images/vae_reconstructed_epoch_3.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_3.png rename to 12-VAE/images/vae_reconstructed_epoch_3.png diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_4.png b/12-VAE/images/vae_reconstructed_epoch_4.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_4.png rename to 12-VAE/images/vae_reconstructed_epoch_4.png diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_5.png b/12-VAE/images/vae_reconstructed_epoch_5.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_5.png rename to 12-VAE/images/vae_reconstructed_epoch_5.png diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_6.png b/12-VAE/images/vae_reconstructed_epoch_6.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_6.png rename to 12-VAE/images/vae_reconstructed_epoch_6.png diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_7.png b/12-VAE/images/vae_reconstructed_epoch_7.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_7.png rename to 12-VAE/images/vae_reconstructed_epoch_7.png diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_8.png b/12-VAE/images/vae_reconstructed_epoch_8.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_8.png rename to 12-VAE/images/vae_reconstructed_epoch_8.png diff --git a/lesson22-VAE/images/vae_reconstructed_epoch_9.png b/12-VAE/images/vae_reconstructed_epoch_9.png similarity index 100% rename from lesson22-VAE/images/vae_reconstructed_epoch_9.png rename to 12-VAE/images/vae_reconstructed_epoch_9.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_1.png b/12-VAE/images/vae_sampled_epoch_1.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_1.png rename to 12-VAE/images/vae_sampled_epoch_1.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_2.png b/12-VAE/images/vae_sampled_epoch_2.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_2.png rename to 12-VAE/images/vae_sampled_epoch_2.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_3.png b/12-VAE/images/vae_sampled_epoch_3.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_3.png rename to 12-VAE/images/vae_sampled_epoch_3.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_4.png b/12-VAE/images/vae_sampled_epoch_4.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_4.png rename to 12-VAE/images/vae_sampled_epoch_4.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_5.png b/12-VAE/images/vae_sampled_epoch_5.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_5.png rename to 12-VAE/images/vae_sampled_epoch_5.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_6.png b/12-VAE/images/vae_sampled_epoch_6.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_6.png rename to 12-VAE/images/vae_sampled_epoch_6.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_7.png b/12-VAE/images/vae_sampled_epoch_7.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_7.png rename to 12-VAE/images/vae_sampled_epoch_7.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_8.png b/12-VAE/images/vae_sampled_epoch_8.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_8.png rename to 12-VAE/images/vae_sampled_epoch_8.png diff --git a/lesson22-VAE/images/vae_sampled_epoch_9.png b/12-VAE/images/vae_sampled_epoch_9.png similarity index 100% rename from lesson22-VAE/images/vae_sampled_epoch_9.png rename to 12-VAE/images/vae_sampled_epoch_9.png diff --git a/lesson22-VAE/main.py b/12-VAE/main.py similarity index 100% rename from lesson22-VAE/main.py rename to 12-VAE/main.py diff --git a/lesson22-VAE/variational_autoencoder.png b/12-VAE/variational_autoencoder.png similarity index 100% rename from lesson22-VAE/variational_autoencoder.png rename to 12-VAE/variational_autoencoder.png diff --git a/lesson23-DCGAN/.gitignore b/13-DCGAN/.gitignore similarity index 100% rename from lesson23-DCGAN/.gitignore rename to 13-DCGAN/.gitignore diff --git a/lesson23-DCGAN/README.md b/13-DCGAN/README.md similarity index 100% rename from lesson23-DCGAN/README.md rename to 13-DCGAN/README.md diff --git a/lesson23-DCGAN/dcgan.png b/13-DCGAN/dcgan.png similarity index 100% rename from lesson23-DCGAN/dcgan.png rename to 13-DCGAN/dcgan.png diff --git a/lesson23-DCGAN/gan.py b/13-DCGAN/gan.py similarity index 100% rename from lesson23-DCGAN/gan.py rename to 13-DCGAN/gan.py diff --git a/lesson23-DCGAN/main.py b/13-DCGAN/main.py similarity index 100% rename from lesson23-DCGAN/main.py rename to 13-DCGAN/main.py diff --git a/lesson24-Pixel2Pixel/.gitignore b/14-Pixel2Pixel/.gitignore similarity index 100% rename from lesson24-Pixel2Pixel/.gitignore rename to 14-Pixel2Pixel/.gitignore diff --git a/lesson24-Pixel2Pixel/README.md b/14-Pixel2Pixel/README.md similarity index 100% rename from lesson24-Pixel2Pixel/README.md rename to 14-Pixel2Pixel/README.md diff --git a/lesson24-Pixel2Pixel/gd.py b/14-Pixel2Pixel/gd.py similarity index 100% rename from lesson24-Pixel2Pixel/gd.py rename to 14-Pixel2Pixel/gd.py diff --git a/lesson24-Pixel2Pixel/main.py b/14-Pixel2Pixel/main.py similarity index 100% rename from lesson24-Pixel2Pixel/main.py rename to 14-Pixel2Pixel/main.py diff --git a/lesson24-Pixel2Pixel/pix2pix.jpg b/14-Pixel2Pixel/pix2pix.jpg similarity index 100% rename from lesson24-Pixel2Pixel/pix2pix.jpg rename to 14-Pixel2Pixel/pix2pix.jpg diff --git a/lesson25-CycleGAN/.gitignore b/15-CycleGAN/.gitignore similarity index 100% rename from lesson25-CycleGAN/.gitignore rename to 15-CycleGAN/.gitignore diff --git a/lesson25-CycleGAN/README.md b/15-CycleGAN/README.md similarity index 100% rename from lesson25-CycleGAN/README.md rename to 15-CycleGAN/README.md diff --git a/lesson25-CycleGAN/cyclegan.jpg b/15-CycleGAN/cyclegan.jpg similarity index 100% rename from lesson25-CycleGAN/cyclegan.jpg rename to 15-CycleGAN/cyclegan.jpg diff --git a/lesson25-CycleGAN/images/generated_0.png b/15-CycleGAN/images/generated_0.png similarity index 100% rename from lesson25-CycleGAN/images/generated_0.png rename to 15-CycleGAN/images/generated_0.png diff --git a/lesson25-CycleGAN/images/generated_40.png b/15-CycleGAN/images/generated_40.png similarity index 100% rename from lesson25-CycleGAN/images/generated_40.png rename to 15-CycleGAN/images/generated_40.png diff --git a/lesson25-CycleGAN/main.py b/15-CycleGAN/main.py similarity index 100% rename from lesson25-CycleGAN/main.py rename to 15-CycleGAN/main.py diff --git a/lesson25-CycleGAN/model.py b/15-CycleGAN/model.py similarity index 100% rename from lesson25-CycleGAN/model.py rename to 15-CycleGAN/model.py diff --git a/lesson26-fasterRCNN/.gitignore b/16-fasterRCNN/.gitignore similarity index 100% rename from lesson26-fasterRCNN/.gitignore rename to 16-fasterRCNN/.gitignore diff --git a/lesson26-fasterRCNN/LICENSE b/16-fasterRCNN/LICENSE similarity index 100% rename from lesson26-fasterRCNN/LICENSE rename to 16-fasterRCNN/LICENSE diff --git a/lesson26-fasterRCNN/README.md b/16-fasterRCNN/README.md similarity index 100% rename from lesson26-fasterRCNN/README.md rename to 16-fasterRCNN/README.md diff --git a/lesson26-fasterRCNN/detection/core/anchor/anchor_generator.py b/16-fasterRCNN/detection/core/anchor/anchor_generator.py similarity index 100% rename from lesson26-fasterRCNN/detection/core/anchor/anchor_generator.py rename to 16-fasterRCNN/detection/core/anchor/anchor_generator.py diff --git a/lesson26-fasterRCNN/detection/core/anchor/anchor_target.py b/16-fasterRCNN/detection/core/anchor/anchor_target.py similarity index 100% rename from lesson26-fasterRCNN/detection/core/anchor/anchor_target.py rename to 16-fasterRCNN/detection/core/anchor/anchor_target.py diff --git a/lesson26-fasterRCNN/detection/core/bbox/bbox_target.py b/16-fasterRCNN/detection/core/bbox/bbox_target.py similarity index 100% rename from lesson26-fasterRCNN/detection/core/bbox/bbox_target.py rename to 16-fasterRCNN/detection/core/bbox/bbox_target.py diff --git a/lesson26-fasterRCNN/detection/core/bbox/geometry.py b/16-fasterRCNN/detection/core/bbox/geometry.py similarity index 100% rename from lesson26-fasterRCNN/detection/core/bbox/geometry.py rename to 16-fasterRCNN/detection/core/bbox/geometry.py diff --git a/lesson26-fasterRCNN/detection/core/bbox/transforms.py b/16-fasterRCNN/detection/core/bbox/transforms.py similarity index 100% rename from lesson26-fasterRCNN/detection/core/bbox/transforms.py rename to 16-fasterRCNN/detection/core/bbox/transforms.py diff --git a/lesson26-fasterRCNN/detection/core/loss/losses.py b/16-fasterRCNN/detection/core/loss/losses.py similarity index 100% rename from lesson26-fasterRCNN/detection/core/loss/losses.py rename to 16-fasterRCNN/detection/core/loss/losses.py diff --git a/lesson26-fasterRCNN/detection/datasets/coco.py b/16-fasterRCNN/detection/datasets/coco.py similarity index 100% rename from lesson26-fasterRCNN/detection/datasets/coco.py rename to 16-fasterRCNN/detection/datasets/coco.py diff --git a/lesson26-fasterRCNN/detection/datasets/data_generator.py b/16-fasterRCNN/detection/datasets/data_generator.py similarity index 100% rename from lesson26-fasterRCNN/detection/datasets/data_generator.py rename to 16-fasterRCNN/detection/datasets/data_generator.py diff --git a/lesson26-fasterRCNN/detection/datasets/transforms.py b/16-fasterRCNN/detection/datasets/transforms.py similarity index 100% rename from lesson26-fasterRCNN/detection/datasets/transforms.py rename to 16-fasterRCNN/detection/datasets/transforms.py diff --git a/lesson26-fasterRCNN/detection/datasets/utils.py b/16-fasterRCNN/detection/datasets/utils.py similarity index 100% rename from lesson26-fasterRCNN/detection/datasets/utils.py rename to 16-fasterRCNN/detection/datasets/utils.py diff --git a/lesson26-fasterRCNN/detection/models/backbones/resnet.py b/16-fasterRCNN/detection/models/backbones/resnet.py similarity index 100% rename from lesson26-fasterRCNN/detection/models/backbones/resnet.py rename to 16-fasterRCNN/detection/models/backbones/resnet.py diff --git a/lesson26-fasterRCNN/detection/models/bbox_heads/bbox_head.py b/16-fasterRCNN/detection/models/bbox_heads/bbox_head.py similarity index 100% rename from lesson26-fasterRCNN/detection/models/bbox_heads/bbox_head.py rename to 16-fasterRCNN/detection/models/bbox_heads/bbox_head.py diff --git a/lesson26-fasterRCNN/detection/models/detectors/faster_rcnn.py b/16-fasterRCNN/detection/models/detectors/faster_rcnn.py similarity index 100% rename from lesson26-fasterRCNN/detection/models/detectors/faster_rcnn.py rename to 16-fasterRCNN/detection/models/detectors/faster_rcnn.py diff --git a/lesson26-fasterRCNN/detection/models/detectors/test_mixins.py b/16-fasterRCNN/detection/models/detectors/test_mixins.py similarity index 100% rename from lesson26-fasterRCNN/detection/models/detectors/test_mixins.py rename to 16-fasterRCNN/detection/models/detectors/test_mixins.py diff --git a/lesson26-fasterRCNN/detection/models/necks/fpn.py b/16-fasterRCNN/detection/models/necks/fpn.py similarity index 100% rename from lesson26-fasterRCNN/detection/models/necks/fpn.py rename to 16-fasterRCNN/detection/models/necks/fpn.py diff --git a/lesson26-fasterRCNN/detection/models/roi_extractors/roi_align.py b/16-fasterRCNN/detection/models/roi_extractors/roi_align.py similarity index 100% rename from lesson26-fasterRCNN/detection/models/roi_extractors/roi_align.py rename to 16-fasterRCNN/detection/models/roi_extractors/roi_align.py diff --git a/lesson26-fasterRCNN/detection/models/rpn_heads/rpn_head.py b/16-fasterRCNN/detection/models/rpn_heads/rpn_head.py similarity index 100% rename from lesson26-fasterRCNN/detection/models/rpn_heads/rpn_head.py rename to 16-fasterRCNN/detection/models/rpn_heads/rpn_head.py diff --git a/lesson26-fasterRCNN/detection/utils/misc.py b/16-fasterRCNN/detection/utils/misc.py similarity index 100% rename from lesson26-fasterRCNN/detection/utils/misc.py rename to 16-fasterRCNN/detection/utils/misc.py diff --git a/lesson26-fasterRCNN/image_demo_ckpt.png b/16-fasterRCNN/image_demo_ckpt.png similarity index 100% rename from lesson26-fasterRCNN/image_demo_ckpt.png rename to 16-fasterRCNN/image_demo_ckpt.png diff --git a/lesson26-fasterRCNN/image_demo_random.png b/16-fasterRCNN/image_demo_random.png similarity index 100% rename from lesson26-fasterRCNN/image_demo_random.png rename to 16-fasterRCNN/image_demo_random.png diff --git a/lesson26-fasterRCNN/inspect_model.ipynb b/16-fasterRCNN/inspect_model.ipynb similarity index 100% rename from lesson26-fasterRCNN/inspect_model.ipynb rename to 16-fasterRCNN/inspect_model.ipynb diff --git a/lesson26-fasterRCNN/inspect_model.py b/16-fasterRCNN/inspect_model.py similarity index 100% rename from lesson26-fasterRCNN/inspect_model.py rename to 16-fasterRCNN/inspect_model.py diff --git a/lesson26-fasterRCNN/roi_test.py b/16-fasterRCNN/roi_test.py similarity index 100% rename from lesson26-fasterRCNN/roi_test.py rename to 16-fasterRCNN/roi_test.py diff --git a/lesson26-fasterRCNN/shot.png b/16-fasterRCNN/shot.png similarity index 100% rename from lesson26-fasterRCNN/shot.png rename to 16-fasterRCNN/shot.png diff --git a/lesson26-fasterRCNN/tf.image.crop_and_resize_test.png b/16-fasterRCNN/tf.image.crop_and_resize_test.png similarity index 100% rename from lesson26-fasterRCNN/tf.image.crop_and_resize_test.png rename to 16-fasterRCNN/tf.image.crop_and_resize_test.png diff --git a/lesson26-fasterRCNN/train_model.ipynb b/16-fasterRCNN/train_model.ipynb similarity index 100% rename from lesson26-fasterRCNN/train_model.ipynb rename to 16-fasterRCNN/train_model.ipynb diff --git a/lesson26-fasterRCNN/train_model.py b/16-fasterRCNN/train_model.py similarity index 100% rename from lesson26-fasterRCNN/train_model.py rename to 16-fasterRCNN/train_model.py diff --git a/lesson26-fasterRCNN/visualize.py b/16-fasterRCNN/visualize.py similarity index 100% rename from lesson26-fasterRCNN/visualize.py rename to 16-fasterRCNN/visualize.py diff --git a/lesson27-A2C/README.md b/17-A2C/README.md similarity index 100% rename from lesson27-A2C/README.md rename to 17-A2C/README.md diff --git a/lesson27-A2C/a2c.py b/17-A2C/a2c.py similarity index 100% rename from lesson27-A2C/a2c.py rename to 17-A2C/a2c.py diff --git a/lesson27-A2C/cartpole.gif b/17-A2C/cartpole.gif similarity index 100% rename from lesson27-A2C/cartpole.gif rename to 17-A2C/cartpole.gif diff --git a/lesson27-A2C/reward.png b/17-A2C/reward.png similarity index 100% rename from lesson27-A2C/reward.png rename to 17-A2C/reward.png diff --git a/lesson28-GPT/README.md b/18-GPT/README.md similarity index 100% rename from lesson28-GPT/README.md rename to 18-GPT/README.md diff --git a/lesson28-GPT/architecture.png b/18-GPT/architecture.png similarity index 100% rename from lesson28-GPT/architecture.png rename to 18-GPT/architecture.png diff --git a/lesson28-GPT/model.py b/18-GPT/model.py similarity index 100% rename from lesson28-GPT/model.py rename to 18-GPT/model.py diff --git a/lesson29-BERT/README.md b/19-BERT/README.md similarity index 100% rename from lesson29-BERT/README.md rename to 19-BERT/README.md diff --git a/lesson29-BERT/__init__.py b/19-BERT/__init__.py similarity index 100% rename from lesson29-BERT/__init__.py rename to 19-BERT/__init__.py diff --git a/lesson29-BERT/architecture.png b/19-BERT/architecture.png similarity index 100% rename from lesson29-BERT/architecture.png rename to 19-BERT/architecture.png diff --git a/lesson29-BERT/bert.py b/19-BERT/bert.py similarity index 100% rename from lesson29-BERT/bert.py rename to 19-BERT/bert.py diff --git a/lesson29-BERT/embedding_similarity/__init__.py b/19-BERT/embedding_similarity/__init__.py similarity index 100% rename from lesson29-BERT/embedding_similarity/__init__.py rename to 19-BERT/embedding_similarity/__init__.py diff --git a/lesson29-BERT/embedding_similarity/embeddings.py b/19-BERT/embedding_similarity/embeddings.py similarity index 100% rename from lesson29-BERT/embedding_similarity/embeddings.py rename to 19-BERT/embedding_similarity/embeddings.py diff --git a/lesson29-BERT/layer_normalization/__init__.py b/19-BERT/layer_normalization/__init__.py similarity index 100% rename from lesson29-BERT/layer_normalization/__init__.py rename to 19-BERT/layer_normalization/__init__.py diff --git a/lesson29-BERT/layer_normalization/layer_normalization.py b/19-BERT/layer_normalization/layer_normalization.py similarity index 100% rename from lesson29-BERT/layer_normalization/layer_normalization.py rename to 19-BERT/layer_normalization/layer_normalization.py diff --git a/lesson29-BERT/layers/__init__.py b/19-BERT/layers/__init__.py similarity index 100% rename from lesson29-BERT/layers/__init__.py rename to 19-BERT/layers/__init__.py diff --git a/lesson29-BERT/layers/conv.py b/19-BERT/layers/conv.py similarity index 100% rename from lesson29-BERT/layers/conv.py rename to 19-BERT/layers/conv.py diff --git a/lesson29-BERT/layers/embedding.py b/19-BERT/layers/embedding.py similarity index 100% rename from lesson29-BERT/layers/embedding.py rename to 19-BERT/layers/embedding.py diff --git a/lesson29-BERT/layers/extract.py b/19-BERT/layers/extract.py similarity index 100% rename from lesson29-BERT/layers/extract.py rename to 19-BERT/layers/extract.py diff --git a/lesson29-BERT/layers/inputs.py b/19-BERT/layers/inputs.py similarity index 100% rename from lesson29-BERT/layers/inputs.py rename to 19-BERT/layers/inputs.py diff --git a/lesson29-BERT/layers/masked.py b/19-BERT/layers/masked.py similarity index 100% rename from lesson29-BERT/layers/masked.py rename to 19-BERT/layers/masked.py diff --git a/lesson29-BERT/layers/pooling.py b/19-BERT/layers/pooling.py similarity index 100% rename from lesson29-BERT/layers/pooling.py rename to 19-BERT/layers/pooling.py diff --git a/lesson29-BERT/loader.py b/19-BERT/loader.py similarity index 100% rename from lesson29-BERT/loader.py rename to 19-BERT/loader.py diff --git a/lesson29-BERT/main.py b/19-BERT/main.py similarity index 100% rename from lesson29-BERT/main.py rename to 19-BERT/main.py diff --git a/lesson29-BERT/multi_head_attention/__init__.py b/19-BERT/multi_head_attention/__init__.py similarity index 100% rename from lesson29-BERT/multi_head_attention/__init__.py rename to 19-BERT/multi_head_attention/__init__.py diff --git a/lesson29-BERT/multi_head_attention/multi_head.py b/19-BERT/multi_head_attention/multi_head.py similarity index 100% rename from lesson29-BERT/multi_head_attention/multi_head.py rename to 19-BERT/multi_head_attention/multi_head.py diff --git a/lesson29-BERT/multi_head_attention/multi_head_attention.py b/19-BERT/multi_head_attention/multi_head_attention.py similarity index 100% rename from lesson29-BERT/multi_head_attention/multi_head_attention.py rename to 19-BERT/multi_head_attention/multi_head_attention.py diff --git a/lesson29-BERT/pointwise_feedforward/__init__.py b/19-BERT/pointwise_feedforward/__init__.py similarity index 100% rename from lesson29-BERT/pointwise_feedforward/__init__.py rename to 19-BERT/pointwise_feedforward/__init__.py diff --git a/lesson29-BERT/pointwise_feedforward/feed_forward.py b/19-BERT/pointwise_feedforward/feed_forward.py similarity index 100% rename from lesson29-BERT/pointwise_feedforward/feed_forward.py rename to 19-BERT/pointwise_feedforward/feed_forward.py diff --git a/lesson29-BERT/position_embedding/__init__.py b/19-BERT/position_embedding/__init__.py similarity index 100% rename from lesson29-BERT/position_embedding/__init__.py rename to 19-BERT/position_embedding/__init__.py diff --git a/lesson29-BERT/position_embedding/pos_embd.py b/19-BERT/position_embedding/pos_embd.py similarity index 100% rename from lesson29-BERT/position_embedding/pos_embd.py rename to 19-BERT/position_embedding/pos_embd.py diff --git a/lesson29-BERT/position_embedding/trig_pos_embd.py b/19-BERT/position_embedding/trig_pos_embd.py similarity index 100% rename from lesson29-BERT/position_embedding/trig_pos_embd.py rename to 19-BERT/position_embedding/trig_pos_embd.py diff --git a/lesson29-BERT/self_attention/__init__.py b/19-BERT/self_attention/__init__.py similarity index 100% rename from lesson29-BERT/self_attention/__init__.py rename to 19-BERT/self_attention/__init__.py diff --git a/lesson29-BERT/self_attention/scaled_dot_attention.py b/19-BERT/self_attention/scaled_dot_attention.py similarity index 100% rename from lesson29-BERT/self_attention/scaled_dot_attention.py rename to 19-BERT/self_attention/scaled_dot_attention.py diff --git a/lesson29-BERT/self_attention/seq_self_attention.py b/19-BERT/self_attention/seq_self_attention.py similarity index 100% rename from lesson29-BERT/self_attention/seq_self_attention.py rename to 19-BERT/self_attention/seq_self_attention.py diff --git a/lesson29-BERT/self_attention/seq_weighted_attention.py b/19-BERT/self_attention/seq_weighted_attention.py similarity index 100% rename from lesson29-BERT/self_attention/seq_weighted_attention.py rename to 19-BERT/self_attention/seq_weighted_attention.py diff --git a/lesson29-BERT/tokenizer.py b/19-BERT/tokenizer.py similarity index 100% rename from lesson29-BERT/tokenizer.py rename to 19-BERT/tokenizer.py diff --git a/lesson29-BERT/transformer/__init__.py b/19-BERT/transformer/__init__.py similarity index 100% rename from lesson29-BERT/transformer/__init__.py rename to 19-BERT/transformer/__init__.py diff --git a/lesson29-BERT/transformer/gelu.py b/19-BERT/transformer/gelu.py similarity index 100% rename from lesson29-BERT/transformer/gelu.py rename to 19-BERT/transformer/gelu.py diff --git a/lesson29-BERT/transformer/transformer.py b/19-BERT/transformer/transformer.py similarity index 100% rename from lesson29-BERT/transformer/transformer.py rename to 19-BERT/transformer/transformer.py diff --git a/lesson30-GCN/README.MD b/20-GCN/README.MD similarity index 100% rename from lesson30-GCN/README.MD rename to 20-GCN/README.MD diff --git a/lesson30-GCN/config.py b/20-GCN/config.py similarity index 100% rename from lesson30-GCN/config.py rename to 20-GCN/config.py diff --git a/lesson30-GCN/inits.py b/20-GCN/inits.py similarity index 100% rename from lesson30-GCN/inits.py rename to 20-GCN/inits.py diff --git a/lesson30-GCN/layers.py b/20-GCN/layers.py similarity index 100% rename from lesson30-GCN/layers.py rename to 20-GCN/layers.py diff --git a/lesson30-GCN/metrics.py b/20-GCN/metrics.py similarity index 100% rename from lesson30-GCN/metrics.py rename to 20-GCN/metrics.py diff --git a/lesson30-GCN/models.py b/20-GCN/models.py similarity index 100% rename from lesson30-GCN/models.py rename to 20-GCN/models.py diff --git a/lesson30-GCN/nohup.out b/20-GCN/nohup.out similarity index 100% rename from lesson30-GCN/nohup.out rename to 20-GCN/nohup.out diff --git a/lesson30-GCN/res/screen.png b/20-GCN/res/screen.png similarity index 100% rename from lesson30-GCN/res/screen.png rename to 20-GCN/res/screen.png diff --git a/lesson30-GCN/train.py b/20-GCN/train.py similarity index 100% rename from lesson30-GCN/train.py rename to 20-GCN/train.py diff --git a/lesson30-GCN/utils.py b/20-GCN/utils.py similarity index 100% rename from lesson30-GCN/utils.py rename to 20-GCN/utils.py diff --git a/21-CN-EN-Translation-BERT/Readme.md b/21-CN-EN-Translation-BERT/Readme.md new file mode 100644 index 0000000..17c6d07 --- /dev/null +++ b/21-CN-EN-Translation-BERT/Readme.md @@ -0,0 +1,23 @@ +# Chinese-to-English Machine Translation + + +# HowTo + +1. install required packages. + +`pip install bert-for-tf2` + +2. `python transformer_train.py` to run naive transformer model. + +3. `python bert_train.py` to run BERT pretrained encoder model. + + +# Screenshot + +1. transformer + +``` +Chinese src: 周四和周五å�‘生在五个çœ�份的炸弹爆炸事件导致四人æ»äº¡ï¼Œå‡ å��人å�—伤,é�è¢åœ°ç‚¹åŒ…括旅游胜地普å�‰å’Œå�Ž æ¬£ã€‚ +Translated : Four weeks and five-week bombings have killed four people and injured dozens of others, including tourism and the likelihood of land grabs. +Real: The bombings in five provinces on Thursday and Friday, including in Phuket and Hua Hin, areas popular with tourists, killed four people and injured dozens. +``` diff --git a/21-CN-EN-Translation-BERT/attention.py b/21-CN-EN-Translation-BERT/attention.py new file mode 100644 index 0000000..9b74add --- /dev/null +++ b/21-CN-EN-Translation-BERT/attention.py @@ -0,0 +1,87 @@ +import tensorflow as tf + +def scaled_dot_product_attention(q, k, v, mask): + matmul_qk = tf.matmul(q, k, transpose_b=True) # (..., seq_len_q, seq_len_k) + + # scale matmul_qk + dk = tf.cast(tf.shape(k)[-1], tf.float32) + scaled_attention_logits = matmul_qk / tf.math.sqrt(dk) + + # add the mask to the scaled tensor. + if mask is not None: + scaled_attention_logits += (mask * -1e9) + + # softmax is normalized on the last axis (seq_len_k) so that the scores + # add up to 1. + attention_weights = tf.nn.softmax(scaled_attention_logits, axis=-1) # (..., seq_len_q, seq_len_k) + + output = tf.matmul(attention_weights, v) # (..., seq_len_q, depth_v) + + return output, attention_weights + + +# ## Multi-head attention + +# In[ ]: + + +class MultiHeadAttention(tf.keras.layers.Layer): + def __init__(self, d_model, num_heads): + super(MultiHeadAttention, self).__init__() + self.num_heads = num_heads + self.d_model = d_model + + assert d_model % self.num_heads == 0 + + self.depth = d_model // self.num_heads + + self.wq = tf.keras.layers.Dense(d_model) + self.wk = tf.keras.layers.Dense(d_model) + self.wv = tf.keras.layers.Dense(d_model) + + self.dense = tf.keras.layers.Dense(d_model) + + def split_heads(self, x, batch_size): + """Split the last dimension into (num_heads, depth). + Transpose the result such that the shape is (batch_size, num_heads, seq_len, depth) + """ + x = tf.reshape(x, (batch_size, -1, self.num_heads, self.depth)) + return tf.transpose(x, perm=[0, 2, 1, 3]) + + def call(self, v, k, q, mask): + batch_size = tf.shape(q)[0] + + q = self.wq(q) # (batch_size, seq_len, d_model) + k = self.wk(k) # (batch_size, seq_len, d_model) + v = self.wv(v) # (batch_size, seq_len, d_model) + + q = self.split_heads(q, batch_size) # (batch_size, num_heads, seq_len_q, depth) + k = self.split_heads(k, batch_size) # (batch_size, num_heads, seq_len_k, depth) + v = self.split_heads(v, batch_size) # (batch_size, num_heads, seq_len_v, depth) + + # scaled_attention.shape == (batch_size, num_heads, seq_len_q, depth) + # attention_weights.shape == (batch_size, num_heads, seq_len_q, seq_len_k) + scaled_attention, attention_weights = scaled_dot_product_attention( + q, k, v, mask) + + scaled_attention = tf.transpose(scaled_attention, + perm=[0, 2, 1, 3]) # (batch_size, seq_len_q, num_heads, depth) + + concat_attention = tf.reshape(scaled_attention, + (batch_size, -1, self.d_model)) # (batch_size, seq_len_q, d_model) + + output = self.dense(concat_attention) # (batch_size, seq_len_q, d_model) + + return output, attention_weights + +def main(): + temp_mha = MultiHeadAttention(d_model=512, num_heads=8) + y = tf.random.uniform((1, 60, 768)) # (batch_size, encoder_sequence, d_model) + q = tf.random.uniform((1, 60, 512)) # (batch_size, encoder_sequence, d_model) + out, attn = temp_mha(y, k=y, q=q, mask=None) + out.shape, attn.shape + + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/21-CN-EN-Translation-BERT/attlayer.py b/21-CN-EN-Translation-BERT/attlayer.py new file mode 100644 index 0000000..8f67bf7 --- /dev/null +++ b/21-CN-EN-Translation-BERT/attlayer.py @@ -0,0 +1,118 @@ +import tensorflow as tf +from attention import MultiHeadAttention +from utils import positional_encoding + +def point_wise_feed_forward_network(d_model, dff): + return tf.keras.Sequential([ + tf.keras.layers.Dense(dff, activation='relu'), # (batch_size, seq_len, dff) + tf.keras.layers.Dense(d_model) # (batch_size, seq_len, d_model) + ]) + + + + + +# ## Decoder Layer and Decoder + +class EncoderLayer(tf.keras.layers.Layer): + def __init__(self, d_model, num_heads, dff, rate=0.1): + super(EncoderLayer, self).__init__() + + self.mha = MultiHeadAttention(d_model, num_heads) + self.ffn = point_wise_feed_forward_network(d_model, dff) + + self.layernorm1 = tf.keras.layers.LayerNormalization(epsilon=1e-6) + self.layernorm2 = tf.keras.layers.LayerNormalization(epsilon=1e-6) + + self.dropout1 = tf.keras.layers.Dropout(rate) + self.dropout2 = tf.keras.layers.Dropout(rate) + + def call(self, x, training, mask): + attn_output, _ = self.mha(x, x, x, mask) # (batch_size, input_seq_len, d_model) + attn_output = self.dropout1(attn_output, training=training) + out1 = self.layernorm1(x + attn_output) # (batch_size, input_seq_len, d_model) + + ffn_output = self.ffn(out1) # (batch_size, input_seq_len, d_model) + ffn_output = self.dropout2(ffn_output, training=training) + out2 = self.layernorm2(out1 + ffn_output) # (batch_size, input_seq_len, d_model) + + return out2 + +# Each decoder layer consists of sublayers: +# +# 1. Masked multi-head attention (with look ahead mask and padding mask) +# +# 2. Multi-head attention (with padding mask). V (value) and K (key) receive the encoder output as inputs. Q (query) receives the output from the masked multi-head attention sublaye +# +# 3. Point wise feed forward networks +# +# Each of these sublayers has a residual connection around it followed by a layer normalization. The output of each sublayer is LayerNorm(x + Sublayer(x)). The normalization is done on the d_model (last) axis. + +# In[ ]: + + +class DecoderLayer(tf.keras.layers.Layer): + def __init__(self, d_model, num_heads, dff, rate=0.1): + super(DecoderLayer, self).__init__() + + self.mha1 = MultiHeadAttention(d_model, num_heads) + self.mha2 = MultiHeadAttention(d_model, num_heads) + + self.ffn = point_wise_feed_forward_network(d_model, dff) + + self.layernorm1 = tf.keras.layers.LayerNormalization(epsilon=1e-6) + self.layernorm2 = tf.keras.layers.LayerNormalization(epsilon=1e-6) + self.layernorm3 = tf.keras.layers.LayerNormalization(epsilon=1e-6) + + self.dropout1 = tf.keras.layers.Dropout(rate) + self.dropout2 = tf.keras.layers.Dropout(rate) + self.dropout3 = tf.keras.layers.Dropout(rate) + + def call(self, x, enc_output, training, + look_ahead_mask, padding_mask): + # enc_output.shape == (batch_size, input_seq_len, d_model) + + attn1, attn_weights_block1 = self.mha1(x, x, x, look_ahead_mask) # (batch_size, target_seq_len, d_model) + attn1 = self.dropout1(attn1, training=training) + out1 = self.layernorm1(attn1 + x) + + attn2, attn_weights_block2 = self.mha2( + enc_output, enc_output, out1, padding_mask) # (batch_size, target_seq_len, d_model) + attn2 = self.dropout2(attn2, training=training) + out2 = self.layernorm2(attn2 + out1) # (batch_size, target_seq_len, d_model) + + ffn_output = self.ffn(out2) # (batch_size, target_seq_len, d_model) + ffn_output = self.dropout3(ffn_output, training=training) + out3 = self.layernorm3(ffn_output + out2) # (batch_size, target_seq_len, d_model) + + return out3, attn_weights_block1, attn_weights_block2 + + + + + + + +def main(): + # In[ ]: + sample_encoder_layer = EncoderLayer(512, 8, 2048) + + sample_encoder_layer_output = sample_encoder_layer( + tf.random.uniform((64, 43, 512)), False, None) + + sample_encoder_layer_output.shape # (batch_size, input_seq_len, d_model) + + + sample_decoder_layer = DecoderLayer(512, 8, 2048) + sample_encoder_output = tf.random.uniform((64, 128, 768)) + + sample_decoder_layer_output, _, _ = sample_decoder_layer( + tf.random.uniform((64, 50, 512)), sample_encoder_output, + False, None, None) + + sample_decoder_layer_output.shape # (batch_size, target_seq_len, d_model) + + +if __name__ == '__main__': + main() + diff --git a/21-CN-EN-Translation-BERT/bert_train.py b/21-CN-EN-Translation-BERT/bert_train.py new file mode 100644 index 0000000..debd5e0 --- /dev/null +++ b/21-CN-EN-Translation-BERT/bert_train.py @@ -0,0 +1,162 @@ +import tensorflow as tf + +import time +import numpy as np +import matplotlib.pyplot as plt +import os + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +gpus = tf.config.experimental.list_physical_devices('GPU') +if gpus: + try: + # Currently, memory growth needs to be the same across GPUs + for gpu in gpus: + tf.config.experimental.set_memory_growth(gpu, True) + logical_gpus = tf.config.experimental.list_logical_devices('GPU') + print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs") + except RuntimeError as e: + # Memory growth must be set before GPUs have been initialized + print(e) + +from tokenizer import get_tokenizer +from bertmodel import Transformer, Config +from utils import CustomSchedule, create_masks +from test import Translator + + + +BUFFER_SIZE = 50000 +BATCH_SIZE = 64 +MAX_SEQ_LENGTH = 128 + +train_dataset, val_dataset, tokenizer_en, tokenizer_zh = \ + get_tokenizer(MAX_SEQ_LENGTH, BATCH_SIZE) + + +config = Config(num_layers=6, d_model=256, dff=1024, num_heads=8) + + +target_vocab_size = tokenizer_en.vocab_size + 2 +dropout_rate = 0.1 + + + + +MODEL_DIR = "chinese_L-12_H-768_A-12" +bert_config_file = os.path.join(MODEL_DIR, "bert_config.json") +bert_ckpt_file = os.path.join(MODEL_DIR, "bert_model.ckpt") + +transformer = Transformer(config=config, + target_vocab_size=target_vocab_size, + bert_config_file=bert_config_file) + +inp = tf.random.uniform((BATCH_SIZE, MAX_SEQ_LENGTH)) +tar_inp = tf.random.uniform((BATCH_SIZE, MAX_SEQ_LENGTH)) +fn_out, _ = transformer(inp, tar_inp, + True, + enc_padding_mask=None, + look_ahead_mask=None, + dec_padding_mask=None) +print(tar_inp.shape) # (batch_size, tar_seq_len) +print(fn_out.shape) # (batch_size, tar_seq_len, target_vocab_size) + +# init bert pre-trained weights +transformer.restore_encoder(bert_ckpt_file) +transformer.summary() + + + +learning_rate = CustomSchedule(config.d_model) + +optimizer = tf.keras.optimizers.Adam(learning_rate, beta_1=0.9, beta_2=0.98, + epsilon=1e-9) + + + +loss_object = tf.keras.losses.SparseCategoricalCrossentropy( + from_logits=True, reduction='none') + +def loss_function(real, pred): + mask = tf.math.logical_not(tf.math.equal(real, 0)) + loss_ = loss_object(real, pred) + + mask = tf.cast(mask, dtype=loss_.dtype) + loss_ *= mask + + return tf.reduce_mean(loss_) + + +train_loss = tf.keras.metrics.Mean(name='train_loss') +train_accuracy = tf.keras.metrics.SparseCategoricalAccuracy( + name='train_accuracy') + + +checkpoint_path = "./zh-en/bert" + +ckpt = tf.train.Checkpoint(transformer=transformer, + optimizer=optimizer) + +ckpt_manager = tf.train.CheckpointManager(ckpt, checkpoint_path, max_to_keep=5) + +# if a checkpoint exists, restore the latest checkpoint. +if ckpt_manager.latest_checkpoint: + ckpt.restore(ckpt_manager.latest_checkpoint) + print('Latest checkpoint restored!!') + + + +@tf.function +def train_step(inp, tar): + tar_inp = tar[:, :-1] + tar_real = tar[:, 1:] + + enc_padding_mask, combined_mask, dec_padding_mask = create_masks(inp, tar_inp) + + with tf.GradientTape() as tape: + predictions, _ = transformer(inp, tar_inp, + True, + enc_padding_mask, + combined_mask, + dec_padding_mask) + loss = loss_function(tar_real, predictions) + + gradients = tape.gradient(loss, transformer.trainable_variables) + optimizer.apply_gradients(zip(gradients, transformer.trainable_variables)) + + train_loss(loss) + train_accuracy(tar_real, predictions) + + +# Chinese is used as the input language and English is the target language. +translator = Translator(tokenizer_zh, tokenizer_en, transformer, MAX_SEQ_LENGTH) + +for epoch in range(4): + + res = translator.do('虽然继承了祖è�«ï¼Œä½†æœ´æ§¿æƒ å·²ç»�è¯�明了自己是个机æ•�而è€�练的政治家。') + + + start = time.time() + + train_loss.reset_states() + train_accuracy.reset_states() + + # inp -> chinese, tar -> english + for (batch, (inp, tar)) in enumerate(train_dataset): + train_step(inp, tar) + + if batch % 500 == 0: + print('Epoch {} Batch {} Loss {:.4f} Accuracy {:.4f}'.format( + epoch + 1, batch, train_loss.result(), train_accuracy.result())) + + if (epoch + 1) % 1 == 0: + ckpt_save_path = ckpt_manager.save() + print('Saving checkpoint for epoch {} at {}'.format(epoch + 1, + ckpt_save_path)) + + print('Epoch {} Loss {:.4f} Accuracy {:.4f}'.format(epoch + 1, + train_loss.result(), + train_accuracy.result())) + + print('Time taken for 1 epoch: {} secs\n'.format(time.time() - start)) + + diff --git a/21-CN-EN-Translation-BERT/bertmodel.py b/21-CN-EN-Translation-BERT/bertmodel.py new file mode 100644 index 0000000..0b3e5a7 --- /dev/null +++ b/21-CN-EN-Translation-BERT/bertmodel.py @@ -0,0 +1,120 @@ +import tensorflow as tf + +from bert import BertModelLayer +from bert.loader import StockBertConfig, load_stock_weights +from bert.loader import map_to_stock_variable_name + + +from utils import positional_encoding +from attlayer import DecoderLayer + +class Config(object): + def __init__(self, num_layers, d_model, dff, num_heads): + self.num_layers = num_layers + self.d_model = d_model + self.dff = dff + self.num_heads = num_heads + + +# In[ ]: + +def build_encoder(config_file): + with tf.io.gfile.GFile(config_file, "r") as reader: + stock_params = StockBertConfig.from_json_string(reader.read()) + bert_params = stock_params.to_bert_model_layer_params() + + return BertModelLayer.from_params(bert_params, name="bert") + + + +class Decoder(tf.keras.layers.Layer): + def __init__(self, num_layers, d_model, num_heads, dff, target_vocab_size, + rate=0.1): + super(Decoder, self).__init__() + + self.d_model = d_model + self.num_layers = num_layers + + self.embedding = tf.keras.layers.Embedding(target_vocab_size, d_model) + self.pos_encoding = positional_encoding(target_vocab_size, self.d_model) + + self.dec_layers = [DecoderLayer(d_model, num_heads, dff, rate) + for _ in range(num_layers)] + self.dropout = tf.keras.layers.Dropout(rate) + + def call(self, x, enc_output, training, + look_ahead_mask, padding_mask): + seq_len = tf.shape(x)[1] + attention_weights = {} + + x = self.embedding(x) # (batch_size, target_seq_len, d_model) + x *= tf.math.sqrt(tf.cast(self.d_model, tf.float32)) + x += self.pos_encoding[:, :seq_len, :] + + x = self.dropout(x, training=training) + + for i in range(self.num_layers): + x, block1, block2 = self.dec_layers[i](x, enc_output, training, + look_ahead_mask, padding_mask) + + attention_weights['decoder_layer{}_block1'.format(i + 1)] = block1 + attention_weights['decoder_layer{}_block2'.format(i + 1)] = block2 + + # x.shape == (batch_size, target_seq_len, d_model) + return x, attention_weights + + + +class Transformer(tf.keras.Model): + def __init__(self, config, + target_vocab_size, + bert_config_file, + bert_training=False, + rate=0.1, + name='transformer'): + super(Transformer, self).__init__(name=name) + + self.encoder = build_encoder(config_file=bert_config_file) + self.encoder.trainable = bert_training + + self.decoder = Decoder(config.num_layers, config.d_model, + config.num_heads, config.dff, target_vocab_size, rate) + + self.final_layer = tf.keras.layers.Dense(target_vocab_size) + + def load_stock_weights(self, bert: BertModelLayer, ckpt_file): + assert isinstance(bert, BertModelLayer), "Expecting a BertModelLayer instance as first argument" + assert tf.compat.v1.train.checkpoint_exists(ckpt_file), "Checkpoint does not exist: {}".format(ckpt_file) + ckpt_reader = tf.train.load_checkpoint(ckpt_file) + + bert_prefix = 'transformer/bert' + + weights = [] + for weight in bert.weights: + stock_name = map_to_stock_variable_name(weight.name, bert_prefix) + if ckpt_reader.has_tensor(stock_name): + value = ckpt_reader.get_tensor(stock_name) + weights.append(value) + else: + raise ValueError("No value for:[{}], i.e.:[{}] in:[{}]".format( + weight.name, stock_name, ckpt_file)) + bert.set_weights(weights) + print("Done loading {} BERT weights from: {} into {} (prefix:{})".format( + len(weights), ckpt_file, bert, bert_prefix)) + + def restore_encoder(self, bert_ckpt_file): + # loading the original pre-trained weights into the BERT layer: + self.load_stock_weights(self.encoder, bert_ckpt_file) + + def call(self, inp, tar, training, enc_padding_mask, + look_ahead_mask, dec_padding_mask): + enc_output = self.encoder(inp, training=self.encoder.trainable) # (batch_size, inp_seq_len, d_model) + + # dec_output.shape == (batch_size, tar_seq_len, d_model) + dec_output, attention_weights = self.decoder( + tar, enc_output, training, look_ahead_mask, dec_padding_mask) + + final_output = self.final_layer(dec_output) # (batch_size, tar_seq_len, target_vocab_size) + + return final_output, attention_weights + diff --git a/21-CN-EN-Translation-BERT/test.py b/21-CN-EN-Translation-BERT/test.py new file mode 100644 index 0000000..844552d --- /dev/null +++ b/21-CN-EN-Translation-BERT/test.py @@ -0,0 +1,177 @@ +import tensorflow as tf + +import time +import numpy as np +import matplotlib.pyplot as plt +import os + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +gpus = tf.config.experimental.list_physical_devices('GPU') +if gpus: + try: + # Currently, memory growth needs to be the same across GPUs + for gpu in gpus: + tf.config.experimental.set_memory_growth(gpu, True) + logical_gpus = tf.config.experimental.list_logical_devices('GPU') + print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs") + except RuntimeError as e: + # Memory growth must be set before GPUs have been initialized + print(e) + + +from utils import create_masks + + +class Translator: + + def __init__(self, tokenizer_zh, tokenize_en, model, MAX_SEQ_LENGTH): + + self.tokenizer_zh = tokenizer_zh + self.tokenizer_en = tokenize_en + self.model = model + self.MAX_SEQ_LENGTH = MAX_SEQ_LENGTH + + + def encode_zh(self, zh): + tokens_zh = self.tokenizer_zh.tokenize(zh) + lang1 = self.tokenizer_zh.convert_tokens_to_ids(['[CLS]'] + tokens_zh + ['[SEP]']) + + return lang1 + + + + + + def evaluate(self, inp_sentence): + # normalize input sentence + inp_sentence = self.encode_zh(inp_sentence) + encoder_input = tf.expand_dims(inp_sentence, 0) + + # as the target is english, the first word to the transformer should be the + # english start token. + decoder_input = [self.tokenizer_en.vocab_size] + output = tf.expand_dims(decoder_input, 0) + + for i in range(self.MAX_SEQ_LENGTH): + enc_padding_mask, combined_mask, dec_padding_mask = create_masks( + encoder_input, output) + + # predictions.shape == (batch_size, seq_len, vocab_size) + predictions, attention_weights = self.model(encoder_input, + output, + False, + enc_padding_mask, + combined_mask, + dec_padding_mask) + + # select the last word from the seq_len dimension + predictions = predictions[:, -1:, :] # (batch_size, 1, vocab_size) + + predicted_id = tf.cast(tf.argmax(predictions, axis=-1), tf.int32) + + # return the result if the predicted_id is equal to the end token + if tf.equal(predicted_id, self.tokenizer_en.vocab_size + 1): + return tf.squeeze(output, axis=0), attention_weights + + # concatentate the predicted_id to the output which is given to the decoder + # as its input. + output = tf.concat([output, predicted_id], axis=-1) + + return tf.squeeze(output, axis=0), attention_weights + + + + + + def plot_attention_weights(self, attention, sentence, result, layer): + fig = plt.figure(figsize=(16, 8)) + + sentence_ids = self.encode_zh(sentence) + + attention = tf.squeeze(attention[layer], axis=0) + + for head in range(attention.shape[0]): + ax = fig.add_subplot(2, 4, head + 1) + + # plot the attention weights + ax.matshow(attention[head][:-1, :], cmap='viridis') + + fontdict = {'fontsize': 10, 'family': 'DFKai-SB'} + + ax.set_xticks(range(len(sentence_ids))) + ax.set_yticks(range(len(result))) + + ax.set_ylim(len(result) - 1.5, -0.5) + + ax.set_xticklabels( + self.tokenizer_zh.convert_ids_to_tokens(sentence_ids), + fontdict=fontdict, rotation=90) + + ax.set_yticklabels([self.tokenizer_en.decode([i]) for i in result + if i < self.tokenizer_en.vocab_size], + fontdict=fontdict) + + ax.set_xlabel('Head {}'.format(head + 1)) + + plt.tight_layout() + plt.show() + + +# In[ ]: + + + def do(self, sentence, plot=''): + result, attention_weights = self.evaluate(sentence) + + predicted_sentence = self.tokenizer_en.decode([i for i in result + if i < self.tokenizer_en.vocab_size]) + + print('Chinese src: {}'.format(sentence)) + print('Translated : {}'.format(predicted_sentence)) + + if plot: + self.plot_attention_weights(attention_weights, sentence, result, plot) + + + + +def main(): + # In[42]: + + sentence_ids = encode_zh("æˆ‘çˆ±ä½ å•Š") + print(tokenizer_zh.convert_ids_to_tokens(sentence_ids)) + + # In[ ]: + + # In[51]: + + translate(transformer, '虽然继承了祖è�«ï¼Œä½†æœ´æ§¿æƒ å·²ç»�è¯�明了自己是个机æ•�而è€�练的政治家——她历ç»�20å¹´æ‰�爬上韩国大国家党最高领导层并æˆ�为全国知å��人物。') + print( + 'Real translation: While Park derives some of her power from her family pedigree, she has proven to be an astute and seasoned politician – one who climbed the Grand National Party’s leadership ladder over the last two decades to emerge as a national figure.') + + # In[59]: + + translate(transformer, "æˆ‘çˆ±ä½ æ˜¯ä¸€ä»¶å¹¸ç¦�的事情。") + + # ## Save weights + + # In[ ]: + + transformer.save_weights('bert_nmt_ckpt') + + # In[49]: + + new_transformer = Transformer(config=config, + target_vocab_size=target_vocab_size, + bert_config_file=bert_config_file) + + fn_out, _ = new_transformer(inp, tar_inp, + True, + look_ahead_mask=None, + dec_padding_mask=None) + new_transformer.load_weights('bert_nmt_ckpt') + + translate(new_transformer, 'æˆ‘çˆ±ä½ ') + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/21-CN-EN-Translation-BERT/tokenizer.py b/21-CN-EN-Translation-BERT/tokenizer.py new file mode 100644 index 0000000..4c832e1 --- /dev/null +++ b/21-CN-EN-Translation-BERT/tokenizer.py @@ -0,0 +1,411 @@ +import tensorflow as tf +import tensorflow_datasets as tfds + + +import collections +import unicodedata +import os,sys +import numpy as np + + + + + +def convert_to_unicode(text): + """Converts `text` to Unicode (if it's not already), assuming utf-8 input.""" + if isinstance(text, str): + return text + elif isinstance(text, bytes): + return text.decode("utf-8", "ignore") + else: + raise ValueError("Unsupported string type: %s" % (type(text))) + + +def load_vocab(vocab_file): + """Loads a vocabulary file into a dictionary.""" + vocab = collections.OrderedDict() + index = 0 + with tf.io.gfile.GFile(vocab_file, "r") as reader: + while True: + token = convert_to_unicode(reader.readline()) + if not token: + break + token = token.strip() + vocab[token] = index + index += 1 + return vocab + + +def whitespace_tokenize(text): + """Runs basic whitespace cleaning and splitting on a piece of text.""" + text = text.strip() + if not text: + return [] + tokens = text.split() + return tokens + + +def convert_by_vocab(vocab, items): + """Converts a sequence of [tokens|ids] using the vocab.""" + output = [] + for item in items: + output.append(vocab[item]) + return output + + +class FullTokenizer(object): + """Runs end-to-end tokenziation.""" + + def __init__(self, vocab_file, do_lower_case=True): + self.vocab = load_vocab(vocab_file) + self.inv_vocab = {v: k for k, v in self.vocab.items()} + self.basic_tokenizer = BasicTokenizer(do_lower_case=do_lower_case) + self.wordpiece_tokenizer = WordpieceTokenizer(vocab=self.vocab) + + def tokenize(self, text): + split_tokens = [] + for token in self.basic_tokenizer.tokenize(text): + for sub_token in self.wordpiece_tokenizer.tokenize(token): + split_tokens.append(sub_token) + + return split_tokens + + def convert_tokens_to_ids(self, tokens): + return convert_by_vocab(self.vocab, tokens) + + def convert_ids_to_tokens(self, ids): + return convert_by_vocab(self.inv_vocab, ids) + + +class BasicTokenizer(object): + """Runs basic tokenization (punctuation splitting, lower casing, etc.).""" + + def __init__(self, do_lower_case=True): + """Constructs a BasicTokenizer. + + Args: + do_lower_case: Whether to lower case the input. + """ + self.do_lower_case = do_lower_case + + def tokenize(self, text): + """Tokenizes a piece of text.""" + text = convert_to_unicode(text) + text = self._clean_text(text) + + # This was added on November 1st, 2018 for the multilingual and Chinese + # models. This is also applied to the English models now, but it doesn't + # matter since the English models were not trained on any Chinese data + # and generally don't have any Chinese data in them (there are Chinese + # characters in the vocabulary because Wikipedia does have some Chinese + # words in the English Wikipedia.). + text = self._tokenize_chinese_chars(text) + + orig_tokens = whitespace_tokenize(text) + split_tokens = [] + for token in orig_tokens: + if self.do_lower_case: + token = token.lower() + token = self._run_strip_accents(token) + split_tokens.extend(self._run_split_on_punc(token)) + + output_tokens = whitespace_tokenize(" ".join(split_tokens)) + return output_tokens + + def _run_strip_accents(self, text): + """Strips accents from a piece of text.""" + text = unicodedata.normalize("NFD", text) + output = [] + for char in text: + cat = unicodedata.category(char) + if cat == "Mn": + continue + output.append(char) + return "".join(output) + + def _run_split_on_punc(self, text): + """Splits punctuation on a piece of text.""" + chars = list(text) + i = 0 + start_new_word = True + output = [] + while i < len(chars): + char = chars[i] + if _is_punctuation(char): + output.append([char]) + start_new_word = True + else: + if start_new_word: + output.append([]) + start_new_word = False + output[-1].append(char) + i += 1 + + return ["".join(x) for x in output] + + def _tokenize_chinese_chars(self, text): + """Adds whitespace around any CJK character.""" + output = [] + for char in text: + cp = ord(char) + if self._is_chinese_char(cp): + output.append(" ") + output.append(char) + output.append(" ") + else: + output.append(char) + return "".join(output) + + def _is_chinese_char(self, cp): + """Checks whether CP is the codepoint of a CJK character.""" + # This defines a "chinese character" as anything in the CJK Unicode block: + # https://en.wikipedia.org/wiki/CJK_Unified_Ideographs_(Unicode_block) + # + # Note that the CJK Unicode block is NOT all Japanese and Korean characters, + # despite its name. The modern Korean Hangul alphabet is a different block, + # as is Japanese Hiragana and Katakana. Those alphabets are used to write + # space-separated words, so they are not treated specially and handled + # like the all of the other languages. + if ((cp >= 0x4E00 and cp <= 0x9FFF) or # + (cp >= 0x3400 and cp <= 0x4DBF) or # + (cp >= 0x20000 and cp <= 0x2A6DF) or # + (cp >= 0x2A700 and cp <= 0x2B73F) or # + (cp >= 0x2B740 and cp <= 0x2B81F) or # + (cp >= 0x2B820 and cp <= 0x2CEAF) or + (cp >= 0xF900 and cp <= 0xFAFF) or # + (cp >= 0x2F800 and cp <= 0x2FA1F)): # + return True + + return False + + def _clean_text(self, text): + """Performs invalid character removal and whitespace cleanup on text.""" + output = [] + for char in text: + cp = ord(char) + if cp == 0 or cp == 0xfffd or _is_control(char): + continue + if _is_whitespace(char): + output.append(" ") + else: + output.append(char) + return "".join(output) + + +class WordpieceTokenizer(object): + """Runs WordPiece tokenziation.""" + + def __init__(self, vocab, unk_token="[UNK]", max_input_chars_per_word=200): + self.vocab = vocab + self.unk_token = unk_token + self.max_input_chars_per_word = max_input_chars_per_word + + def tokenize(self, text): + """Tokenizes a piece of text into its word pieces. + + This uses a greedy longest-match-first algorithm to perform tokenization + using the given vocabulary. + + For example: + input = "unaffable" + output = ["un", "##aff", "##able"] + + Args: + text: A single token or whitespace separated tokens. This should have + already been passed through `BasicTokenizer. + + Returns: + A list of wordpiece tokens. + """ + + text = convert_to_unicode(text) + + output_tokens = [] + for token in whitespace_tokenize(text): + chars = list(token) + if len(chars) > self.max_input_chars_per_word: + output_tokens.append(self.unk_token) + continue + + is_bad = False + start = 0 + sub_tokens = [] + while start < len(chars): + end = len(chars) + cur_substr = None + while start < end: + substr = "".join(chars[start:end]) + if start > 0: + substr = "##" + substr + if substr in self.vocab: + cur_substr = substr + break + end -= 1 + if cur_substr is None: + is_bad = True + break + sub_tokens.append(cur_substr) + start = end + + if is_bad: + output_tokens.append(self.unk_token) + else: + output_tokens.extend(sub_tokens) + return output_tokens + + +def _is_whitespace(char): + """Checks whether `chars` is a whitespace character.""" + # \t, \n, and \r are technically contorl characters but we treat them + # as whitespace since they are generally considered as such. + if char == " " or char == "\t" or char == "\n" or char == "\r": + return True + cat = unicodedata.category(char) + if cat == "Zs": + return True + return False + + +def _is_control(char): + """Checks whether `chars` is a control character.""" + # These are technically control characters but we count them as whitespace + # characters. + if char == "\t" or char == "\n" or char == "\r": + return False + cat = unicodedata.category(char) + if cat.startswith("C"): + return True + return False + + +def _is_punctuation(char): + """Checks whether `chars` is a punctuation character.""" + cp = ord(char) + # We treat all non-letter/number ASCII as punctuation. + # Characters such as "^", "$", and "`" are not in the Unicode + # Punctuation class but we treat them as punctuation anyways, for + # consistency. + if ((cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or + (cp >= 91 and cp <= 96) or (cp >= 123 and cp <= 126)): + return True + cat = unicodedata.category(char) + if cat.startswith("P"): + return True + return False + + + + +def get_tokenizer(MAX_SEQ_LENGTH, BATCH_SIZE): + # ## Setup input pipleline + + # Use TFDS to load the wmt2019 zh-en translation dataset. + + if not os.path.exists('chinese_L-12_H-768_A-12'): + # get_ipython().system('wget https://storage.googleapis.com/bert_models/2018_11_03/chinese_L-12_H-768_A-12.zip') + # get_ipython().system('unzip chinese_L-12_H-768_A-12') + print('download pretrained first!') + sys.exit() + + config = tfds.translate.wmt.WmtConfig( + description="WMT 2019 translation task dataset.", + version="0.0.3", + language_pair=("zh", "en"), + subsets={ + tfds.Split.TRAIN: ["newscommentary_v13"], + tfds.Split.VALIDATION: ["newsdev2017"], + } + ) + + builder = tfds.builder("wmt_translate", config=config) + print(builder.info.splits) + builder.download_and_prepare() + datasets = builder.as_dataset(as_supervised=True) + print('datasets is {}'.format(datasets)) + + # In[ ]: + + train_examples = datasets['train'] + val_examples = datasets['validation'] + + # In[ ]: + + for zh, en in train_examples.take(1): + # print((zh)) + print(tf.compat.as_text(zh.numpy())) + print(tf.compat.as_text(en.numpy())) + + # Create a custom subwords tokenizer from the training dataset for the decoder. + + # In[ ]: + + vocab_file = 'vocab_en' + if os.path.isfile(vocab_file + '.subwords'): + tokenizer_en = tfds.features.text.SubwordTextEncoder.load_from_file(vocab_file) + else: + tokenizer_en = tfds.features.text.SubwordTextEncoder.build_from_corpus( + (en.numpy() for zh, en in train_examples), target_vocab_size=2 ** 13) + tokenizer_en.save_to_file('vocab_en') + + sample_string = 'Transformer is awesome.' + tokenized_string = tokenizer_en.encode(sample_string) + for ts in tokenized_string: + print('{} ----> {}'.format(ts, tokenizer_en.decode([ts]))) + + # The encoder uses BERT tokenizer. + + # In[ ]: + + tokenizer_zh = FullTokenizer( + vocab_file='chinese_L-12_H-768_A-12/vocab.txt', do_lower_case=True) + + test_tokens = tokenizer_zh.tokenize('今天天气ä¸�é”™é¢�。') + test_ids = tokenizer_zh.convert_tokens_to_ids(['[CLS]'] + test_tokens + ['[SEP]']) + print('tokens:', test_tokens) + print('ids:', test_ids) + print('convert_ids_to_tokens:', tokenizer_zh.convert_ids_to_tokens(test_ids)) + + + def encode(zh, en, seq_length=MAX_SEQ_LENGTH): + tokens_zh = tokenizer_zh.tokenize(tf.compat.as_text(zh.numpy())) + lang1 = tokenizer_zh.convert_tokens_to_ids(['[CLS]'] + tokens_zh + ['[SEP]']) + if len(lang1) < seq_length: + lang1 = lang1 + list(np.zeros(seq_length - len(lang1), 'int32')) + + # insert SOS and EOS + lang2 = [tokenizer_en.vocab_size] + tokenizer_en.encode( + tf.compat.as_text(en.numpy())) + [tokenizer_en.vocab_size + 1] + if len(lang2) < seq_length: + lang2 = lang2 + list(np.zeros(seq_length - len(lang2), 'int32')) + + return lang1, lang2 + + + + def filter_max_length(x, y, max_length=MAX_SEQ_LENGTH): + return tf.logical_and(tf.size(x) <= max_length, + tf.size(y) <= max_length) + + train_dataset = train_examples.map( + lambda zh, en: tf.py_function(encode, [zh, en], [tf.int32, tf.int32])) + train_dataset = train_dataset.filter(filter_max_length) + + # cache the dataset to memory to get a speedup while reading from it. + train_dataset = train_dataset.cache() + train_dataset = train_dataset.shuffle(20000).padded_batch( + BATCH_SIZE, padded_shapes=([-1], [-1]), drop_remainder=True) + train_dataset = train_dataset.prefetch(tf.data.experimental.AUTOTUNE) + + val_dataset = val_examples.map( + lambda zh, en: tf.py_function(encode, [zh, en], [tf.int32, tf.int32])) + val_dataset = val_dataset.filter(filter_max_length) + val_dataset = val_dataset.padded_batch(BATCH_SIZE, padded_shapes=([-1], [-1])) + + + + + return train_dataset, val_dataset, tokenizer_en, tokenizer_zh + + +if __name__ == '__main__': + get_tokenizer(100, 64) \ No newline at end of file diff --git a/21-CN-EN-Translation-BERT/transformer.py b/21-CN-EN-Translation-BERT/transformer.py new file mode 100644 index 0000000..b70014d --- /dev/null +++ b/21-CN-EN-Translation-BERT/transformer.py @@ -0,0 +1,158 @@ +import tensorflow as tf +import numpy as np + +from utils import positional_encoding +from attlayer import EncoderLayer,DecoderLayer + + + +class Encoder(tf.keras.layers.Layer): + def __init__(self, num_layers, d_model, num_heads, dff, input_vocab_size, + rate=0.1): + super(Encoder, self).__init__() + + self.d_model = d_model + self.num_layers = num_layers + + self.embedding = tf.keras.layers.Embedding(input_vocab_size, d_model) + self.pos_encoding = positional_encoding(input_vocab_size, self.d_model) + + self.enc_layers = [EncoderLayer(d_model, num_heads, dff, rate) + for _ in range(num_layers)] + + self.dropout = tf.keras.layers.Dropout(rate) + + def call(self, x, training, mask): + seq_len = tf.shape(x)[1] + + # adding embedding and position encoding. + x = self.embedding(x) # (batch_size, input_seq_len, d_model) + x *= tf.math.sqrt(tf.cast(self.d_model, tf.float32)) + x += self.pos_encoding[:, :seq_len, :] + + x = self.dropout(x, training=training) + + for i in range(self.num_layers): + x = self.enc_layers[i](x, training, mask) + + return x # (batch_size, input_seq_len, d_model) + + +"""### Decoder + +The `Decoder` consists of: +1. Output Embedding +2. Positional Encoding +3. N decoder layers + +The target is put through an embedding which is summed with the positional encoding. The output of this summation is the input to the decoder layers. The output of the decoder is the input to the final linear layer. +""" + + +class Decoder(tf.keras.layers.Layer): + def __init__(self, num_layers, d_model, num_heads, dff, target_vocab_size, + rate=0.1): + super(Decoder, self).__init__() + + self.d_model = d_model + self.num_layers = num_layers + + self.embedding = tf.keras.layers.Embedding(target_vocab_size, d_model) + self.pos_encoding = positional_encoding(target_vocab_size, self.d_model) + + self.dec_layers = [DecoderLayer(d_model, num_heads, dff, rate) + for _ in range(num_layers)] + self.dropout = tf.keras.layers.Dropout(rate) + + def call(self, x, enc_output, training, + look_ahead_mask, padding_mask): + seq_len = tf.shape(x)[1] + attention_weights = {} + + x = self.embedding(x) # (batch_size, target_seq_len, d_model) + x *= tf.math.sqrt(tf.cast(self.d_model, tf.float32)) + x += self.pos_encoding[:, :seq_len, :] + + x = self.dropout(x, training=training) + + for i in range(self.num_layers): + x, block1, block2 = self.dec_layers[i](x, enc_output, training, + look_ahead_mask, padding_mask) + + attention_weights['decoder_layer{}_block1'.format(i + 1)] = block1 + attention_weights['decoder_layer{}_block2'.format(i + 1)] = block2 + + # x.shape == (batch_size, target_seq_len, d_model) + return x, attention_weights + + + +"""## Create the Transformer + +Transformer consists of the encoder, decoder and a final linear layer. The output of the decoder is the input to the linear layer and its output is returned. +""" + + +class Transformer(tf.keras.Model): + def __init__(self, num_layers, d_model, num_heads, dff, input_vocab_size, + target_vocab_size, rate=0.1): + super(Transformer, self).__init__() + + self.encoder = Encoder(num_layers, d_model, num_heads, dff, + input_vocab_size, rate) + + self.decoder = Decoder(num_layers, d_model, num_heads, dff, + target_vocab_size, rate) + + self.final_layer = tf.keras.layers.Dense(target_vocab_size) + + def call(self, inp, tar, training, enc_padding_mask, + look_ahead_mask, dec_padding_mask): + enc_output = self.encoder(inp, training, enc_padding_mask) # (batch_size, inp_seq_len, d_model) + + # dec_output.shape == (batch_size, tar_seq_len, d_model) + dec_output, attention_weights = self.decoder( + tar, enc_output, training, look_ahead_mask, dec_padding_mask) + + final_output = self.final_layer(dec_output) # (batch_size, tar_seq_len, target_vocab_size) + + return final_output, attention_weights + + + + + +if __name__ == '__main__': + sample_encoder = Encoder(num_layers=2, d_model=512, num_heads=8, + dff=2048, input_vocab_size=8500) + + sample_encoder_output = sample_encoder(tf.random.uniform((64, 62)), + training=False, mask=None) + + print(sample_encoder_output.shape) # (batch_size, input_seq_len, d_model) + + sample_decoder = Decoder(num_layers=2, d_model=512, num_heads=8, + dff=2048, target_vocab_size=8000) + + output, attn = sample_decoder(tf.random.uniform((64, 26)), + enc_output=sample_encoder_output, + training=False, look_ahead_mask=None, + padding_mask=None) + + output.shape, attn['decoder_layer2_block2'].shape + + + sample_transformer = Transformer( + num_layers=2, d_model=512, num_heads=8, dff=2048, + input_vocab_size=8500, target_vocab_size=8000) + + temp_input = tf.random.uniform((64, 62)) + temp_target = tf.random.uniform((64, 26)) + + fn_out, _ = sample_transformer(temp_input, temp_target, training=False, + enc_padding_mask=None, + look_ahead_mask=None, + dec_padding_mask=None) + + fn_out.shape # (batch_size, tar_seq_len, target_vocab_size) + diff --git a/21-CN-EN-Translation-BERT/transformer_train.py b/21-CN-EN-Translation-BERT/transformer_train.py new file mode 100644 index 0000000..569ee70 --- /dev/null +++ b/21-CN-EN-Translation-BERT/transformer_train.py @@ -0,0 +1,169 @@ +import tensorflow as tf + +import time +import numpy as np +import matplotlib.pyplot as plt +import os + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +gpus = tf.config.experimental.list_physical_devices('GPU') +if gpus: + try: + # Currently, memory growth needs to be the same across GPUs + for gpu in gpus: + tf.config.experimental.set_memory_growth(gpu, True) + logical_gpus = tf.config.experimental.list_logical_devices('GPU') + print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs") + except RuntimeError as e: + # Memory growth must be set before GPUs have been initialized + print(e) + +from tokenizer import get_tokenizer +from transformer import Transformer +from utils import CustomSchedule, create_masks +from test import Translator + + + + +BUFFER_SIZE = 20000 +BATCH_SIZE = 64 +MAX_SEQ_LENGTH = 128 + +train_dataset, val_dataset, tokenizer_en, tokenizer_zh = \ + get_tokenizer(MAX_SEQ_LENGTH, BATCH_SIZE) + +# Chinese -> English translation +input_vocab_size = 21128 +target_vocab_size = tokenizer_en.vocab_size + 2 +dropout_rate = 0.1 +num_layers=4 +d_model=512 +dff=2048 +num_heads=8 + +transformer = Transformer(num_layers, d_model, num_heads, dff, + input_vocab_size, target_vocab_size, dropout_rate) + +inp = tf.random.uniform((BATCH_SIZE, MAX_SEQ_LENGTH)) +tar_inp = tf.random.uniform((BATCH_SIZE, MAX_SEQ_LENGTH)) + +fn_out, _ = transformer(inp, tar_inp, + True, + enc_padding_mask=None, + look_ahead_mask=None, + dec_padding_mask=None) +print(tar_inp.shape) # (batch_size, tar_seq_len) +print(fn_out.shape) # (batch_size, tar_seq_len, target_vocab_size) +transformer.summary() + + + +learning_rate = CustomSchedule(d_model) + +optimizer = tf.keras.optimizers.Adam(learning_rate, beta_1=0.9, beta_2=0.98, + epsilon=1e-9) + + + +loss_object = tf.keras.losses.SparseCategoricalCrossentropy( + from_logits=True, reduction='none') + +def loss_function(real, pred): + mask = tf.math.logical_not(tf.math.equal(real, 0)) + loss_ = loss_object(real, pred) + + mask = tf.cast(mask, dtype=loss_.dtype) + loss_ *= mask + + return tf.reduce_mean(loss_) + + +train_loss = tf.keras.metrics.Mean(name='train_loss') +train_accuracy = tf.keras.metrics.SparseCategoricalAccuracy( + name='train_accuracy') + + +checkpoint_path = "./zh-en/transformer" + +ckpt = tf.train.Checkpoint(transformer=transformer, + optimizer=optimizer) + +ckpt_manager = tf.train.CheckpointManager(ckpt, checkpoint_path, max_to_keep=5) + +# if a checkpoint exists, restore the latest checkpoint. +if ckpt_manager.latest_checkpoint: + ckpt.restore(ckpt_manager.latest_checkpoint) + print('Latest checkpoint restored!!') + + + +@tf.function +def train_step(inp, tar): + tar_inp = tar[:, :-1] + tar_real = tar[:, 1:] + + enc_padding_mask, combined_mask, dec_padding_mask = create_masks(inp, tar_inp) + + with tf.GradientTape() as tape: + predictions, _ = transformer(inp, tar_inp, + True, + enc_padding_mask, + combined_mask, + dec_padding_mask) + loss = loss_function(tar_real, predictions) + + gradients = tape.gradient(loss, transformer.trainable_variables) + optimizer.apply_gradients(zip(gradients, transformer.trainable_variables)) + + train_loss(loss) + train_accuracy(tar_real, predictions) + + +# Chinese is used as the input language and English is the target language. +translator = Translator(tokenizer_zh, tokenizer_en, transformer, MAX_SEQ_LENGTH) + +for epoch in range(20): + + (cn_code, en_code) = next(iter(val_dataset)) + cn_code, en_code = cn_code[epoch].numpy(), en_code[epoch].numpy() + # print(cn_code) + # print(en_code) + en = tokenizer_en.decode([i for i in en_code if i < tokenizer_en.vocab_size]) + cn_code = [int(i) + for i in cn_code if (i!=101 and i!=102 and i!=1 and i!=0)] + # print(cn_code) + cn = tokenizer_zh.convert_ids_to_tokens(cn_code) + cn = "".join(cn) + translator.do(cn) + print('Real:', en) + print('\n') + + + + start = time.time() + + train_loss.reset_states() + train_accuracy.reset_states() + + # inp -> chinese, tar -> english + for (batch, (inp, tar)) in enumerate(train_dataset): + train_step(inp, tar) + + if batch % 50 == 0: + print('Epoch {} Batch {} Loss {:.4f} Accuracy {:.4f}'.format( + epoch + 1, batch, train_loss.result(), train_accuracy.result())) + + if (epoch + 1) % 3 == 0: + ckpt_save_path = ckpt_manager.save() + print('Saving checkpoint for epoch {} at {}'.format(epoch + 1, + ckpt_save_path)) + + print('Epoch {} Loss {:.4f} Accuracy {:.4f}'.format(epoch + 1, + train_loss.result(), + train_accuracy.result())) + + print('Time taken for 1 epoch: {} secs\n'.format(time.time() - start)) + + + diff --git a/21-CN-EN-Translation-BERT/utils.py b/21-CN-EN-Translation-BERT/utils.py new file mode 100644 index 0000000..adb3651 --- /dev/null +++ b/21-CN-EN-Translation-BERT/utils.py @@ -0,0 +1,117 @@ + +import tensorflow as tf +import numpy as np +import matplotlib.pyplot as plt + +def get_angles(pos, i, d_model): + angle_rates = 1 / np.power(10000, (2 * (i // 2)) / np.float32(d_model)) + return pos * angle_rates + + +def positional_encoding(position, d_model): + angle_rads = get_angles(np.arange(position)[:, np.newaxis], + np.arange(d_model)[np.newaxis, :], + d_model) + + # apply sin to even indices in the array; 2i + sines = np.sin(angle_rads[:, 0::2]) + + # apply cos to odd indices in the array; 2i+1 + cosines = np.cos(angle_rads[:, 1::2]) + + pos_encoding = np.concatenate([sines, cosines], axis=-1) + + pos_encoding = pos_encoding[np.newaxis, ...] + + return tf.cast(pos_encoding, dtype=tf.float32) + + +# ## Masking + +# Mask all the pad tokens in the batch of sequence. It ensures that the model does not treat padding as the input. The mask indicates where pad value 0 is present: it outputs a 1 at those locations, and a 0 otherwise. + +# In[ ]: + + +def create_padding_mask(seq): + seq = tf.cast(tf.math.equal(seq, 0), tf.float32) + + # add extra dimensions so that we can add the padding + # to the attention logits. + return seq[:, tf.newaxis, tf.newaxis, :] # (batch_size, 1, 1, seq_len) + + +# The look-ahead mask is used to mask the future tokens in a sequence. In other words, the mask indicates which entries should not be used. +# +# This means that to predict the third word, only the first and second word will be used. Similarly to predict the fourth word, only the first, second and the third word will be used and so on. + +# In[ ]: + + +def create_look_ahead_mask(size): + mask = 1 - tf.linalg.band_part(tf.ones((size, size)), -1, 0) + return mask # (seq_len, seq_len) + + +def create_masks(inp, tar): + # Encoder padding mask + enc_padding_mask = create_padding_mask(inp) + + # Used in the 2nd attention block in the decoder. + # This padding mask is used to mask the encoder outputs. + dec_padding_mask = create_padding_mask(inp) + + # Used in the 1st attention block in the decoder. + # It is used to pad and mask future tokens in the input received by + # the decoder. + look_ahead_mask = create_look_ahead_mask(tf.shape(tar)[1]) + dec_target_padding_mask = create_padding_mask(tar) + combined_mask = tf.maximum(dec_target_padding_mask, look_ahead_mask) + + return enc_padding_mask, combined_mask, dec_padding_mask + +# def create_masks2(inp, tar): +# # Used in the 2nd attention block in the decoder. +# # This padding mask is used to mask the encoder outputs. +# dec_padding_mask = create_padding_mask(inp) +# +# # Used in the 1st attention block in the decoder. +# # It is used to pad and mask future tokens in the input received by +# # the decoder. +# look_ahead_mask = create_look_ahead_mask(tf.shape(tar)[1]) +# dec_target_padding_mask = create_padding_mask(tar) +# combined_mask = tf.maximum(dec_target_padding_mask, look_ahead_mask) +# +# return combined_mask, dec_padding_mask + + +class CustomSchedule(tf.keras.optimizers.schedules.LearningRateSchedule): + def __init__(self, d_model, warmup_steps=4000): + super(CustomSchedule, self).__init__() + + self.d_model = d_model + self.d_model = tf.cast(self.d_model, tf.float32) + + self.warmup_steps = warmup_steps + + def __call__(self, step): + arg1 = tf.math.rsqrt(step) + arg2 = step * (self.warmup_steps ** -1.5) + + return tf.math.rsqrt(self.d_model) * tf.math.minimum(arg1, arg2) + + + +def main(): + # In[ ]: + + temp_learning_rate_schedule = CustomSchedule(config.d_model) + + plt.plot(temp_learning_rate_schedule(tf.range(40000, dtype=tf.float32))) + plt.ylabel("Learning Rate") + plt.xlabel("Train Step") + + +if __name__ == '__main__': + main() + diff --git a/README.md b/README.md index c9e5a7d..3c7e1f2 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Our repo. is the **Winner** of [âš¡#PoweredByTF 2.0 Challenge!](https://devpost.
Timeline: +- Oct. 1, 2019: TensorFlow 2.0 Stable! +- Aug. 24, 2019: [TensorFlow 2.0 rc0](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf) - Jun. 8, 2019: [TensorFlow 2.0 Beta](https://twitter.com/fchollet/status/1134583289384120320) - Mar. 7, 2019: [Tensorflow 2.0 Alpha](https://www.tensorflow.org/alpha) - Jan. 11, 2019: [TensorFlow r2.0 preview](https://www.tensorflow.org/versions/r2.0/api_docs/python/tf) @@ -20,7 +22,7 @@ make sure you are using python 3.x. - CPU install ```python -pip install tensorflow==2.0.0-beta0 +pip install tensorflow -U ``` - GPU install @@ -28,7 +30,7 @@ pip install tensorflow==2.0.0-beta0 Install `CUDA 10.0`(or after) and `cudnn` by yourself. and set `LD_LIBRARY_PATH` up. ```python -pip install tensorflow-gpu==2.0.0-beta0 +pip install tensorflow-gpu -U ``` Test installation: @@ -36,7 +38,7 @@ Test installation: In [2]: import tensorflow as tf In [3]: tf.__version__ -Out[3]: '2.0.0-dev20190129' +Out[3]: '2.0.0' In [4]: tf.test.is_gpu_available() ... totalMemory: 3.95GiB freeMemory: 3.00GiB @@ -46,6 +48,27 @@ Out[4]: True ``` + + +# é…�套TF2视频教程 + + + +TensorFlow 2.0的视频教程链接:[深度å¦ä¹ 与TensorFlow 2实战](https://study.163.com/course/courseMain.htm?share=2&shareId=480000001847407&courseId=1209092816&_trace_c_p_k2_=dca16f8fd11a4525bac8c89f779b2cfa) + + +# Acknowledgement +- 爱å�¯å�¯-爱生活 å�‹æƒ…推è��  + + # Includes - TensorFlow 2.0 Overview @@ -76,7 +99,6 @@ Feel free to submit a **PR** request to make this repo. more complete! - # Refered Repos. Our work is not built from scratch. Great appreciation to these open worksï¼� @@ -87,24 +109,5 @@ Our work is not built from scratch. Great appreciation to these open worksï¼� - https://github.com/moono/tf-eager-on-GAN - https://github.com/Viredery/tf-eager-fasterrcnn - https://github.com/github/gitignore/blob/master/Python.gitignore -- - -# é…�套视频教程 - - - -TensorFlow 2.0的视频教程链接:[深度å¦ä¹ 与TensorFlow 2实战](https://study.163.com/course/courseMain.htm?share=2&shareId=480000001847407&courseId=1209092816&_trace_c_p_k2_=dca16f8fd11a4525bac8c89f779b2cfa) - - -# Acknowledgement -- 爱å�¯å�¯-爱生活 å�‹æƒ…推è��  diff --git a/lesson29-BERT/embedding_similarity/__pycache__/__init__.cpython-36.pyc b/lesson29-BERT/embedding_similarity/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 94e26a1..0000000 Binary files a/lesson29-BERT/embedding_similarity/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/embedding_similarity/__pycache__/embeddings.cpython-36.pyc b/lesson29-BERT/embedding_similarity/__pycache__/embeddings.cpython-36.pyc deleted file mode 100644 index 0e14287..0000000 Binary files a/lesson29-BERT/embedding_similarity/__pycache__/embeddings.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layer_normalization/__pycache__/__init__.cpython-36.pyc b/lesson29-BERT/layer_normalization/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index d533872..0000000 Binary files a/lesson29-BERT/layer_normalization/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layer_normalization/__pycache__/layer_normalization.cpython-36.pyc b/lesson29-BERT/layer_normalization/__pycache__/layer_normalization.cpython-36.pyc deleted file mode 100644 index 1844135..0000000 Binary files a/lesson29-BERT/layer_normalization/__pycache__/layer_normalization.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layers/__pycache__/__init__.cpython-36.pyc b/lesson29-BERT/layers/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 4add457..0000000 Binary files a/lesson29-BERT/layers/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layers/__pycache__/conv.cpython-36.pyc b/lesson29-BERT/layers/__pycache__/conv.cpython-36.pyc deleted file mode 100644 index 0a19fbb..0000000 Binary files a/lesson29-BERT/layers/__pycache__/conv.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layers/__pycache__/embedding.cpython-36.pyc b/lesson29-BERT/layers/__pycache__/embedding.cpython-36.pyc deleted file mode 100644 index 329eedc..0000000 Binary files a/lesson29-BERT/layers/__pycache__/embedding.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layers/__pycache__/extract.cpython-36.pyc b/lesson29-BERT/layers/__pycache__/extract.cpython-36.pyc deleted file mode 100644 index 54d1175..0000000 Binary files a/lesson29-BERT/layers/__pycache__/extract.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layers/__pycache__/inputs.cpython-36.pyc b/lesson29-BERT/layers/__pycache__/inputs.cpython-36.pyc deleted file mode 100644 index 641033b..0000000 Binary files a/lesson29-BERT/layers/__pycache__/inputs.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layers/__pycache__/masked.cpython-36.pyc b/lesson29-BERT/layers/__pycache__/masked.cpython-36.pyc deleted file mode 100644 index 1ea57e4..0000000 Binary files a/lesson29-BERT/layers/__pycache__/masked.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/layers/__pycache__/pooling.cpython-36.pyc b/lesson29-BERT/layers/__pycache__/pooling.cpython-36.pyc deleted file mode 100644 index 4595208..0000000 Binary files a/lesson29-BERT/layers/__pycache__/pooling.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/multi_head_attention/__pycache__/__init__.cpython-36.pyc b/lesson29-BERT/multi_head_attention/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index f65d72b..0000000 Binary files a/lesson29-BERT/multi_head_attention/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/multi_head_attention/__pycache__/multi_head.cpython-36.pyc b/lesson29-BERT/multi_head_attention/__pycache__/multi_head.cpython-36.pyc deleted file mode 100644 index dd96783..0000000 Binary files a/lesson29-BERT/multi_head_attention/__pycache__/multi_head.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/multi_head_attention/__pycache__/multi_head_attention.cpython-36.pyc b/lesson29-BERT/multi_head_attention/__pycache__/multi_head_attention.cpython-36.pyc deleted file mode 100644 index 0caa11d..0000000 Binary files a/lesson29-BERT/multi_head_attention/__pycache__/multi_head_attention.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/pointwise_feedforward/__pycache__/__init__.cpython-36.pyc b/lesson29-BERT/pointwise_feedforward/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index becdcc6..0000000 Binary files a/lesson29-BERT/pointwise_feedforward/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/pointwise_feedforward/__pycache__/feed_forward.cpython-36.pyc b/lesson29-BERT/pointwise_feedforward/__pycache__/feed_forward.cpython-36.pyc deleted file mode 100644 index 624c2b0..0000000 Binary files a/lesson29-BERT/pointwise_feedforward/__pycache__/feed_forward.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/position_embedding/__pycache__/__init__.cpython-36.pyc b/lesson29-BERT/position_embedding/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index f752fcb..0000000 Binary files a/lesson29-BERT/position_embedding/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/position_embedding/__pycache__/pos_embd.cpython-36.pyc b/lesson29-BERT/position_embedding/__pycache__/pos_embd.cpython-36.pyc deleted file mode 100644 index 39cca52..0000000 Binary files a/lesson29-BERT/position_embedding/__pycache__/pos_embd.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/position_embedding/__pycache__/trig_pos_embd.cpython-36.pyc b/lesson29-BERT/position_embedding/__pycache__/trig_pos_embd.cpython-36.pyc deleted file mode 100644 index 1566147..0000000 Binary files a/lesson29-BERT/position_embedding/__pycache__/trig_pos_embd.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/self_attention/__pycache__/__init__.cpython-36.pyc b/lesson29-BERT/self_attention/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 2bc2ce9..0000000 Binary files a/lesson29-BERT/self_attention/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/self_attention/__pycache__/scaled_dot_attention.cpython-36.pyc b/lesson29-BERT/self_attention/__pycache__/scaled_dot_attention.cpython-36.pyc deleted file mode 100644 index f58ef64..0000000 Binary files a/lesson29-BERT/self_attention/__pycache__/scaled_dot_attention.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/self_attention/__pycache__/seq_self_attention.cpython-36.pyc b/lesson29-BERT/self_attention/__pycache__/seq_self_attention.cpython-36.pyc deleted file mode 100644 index 4152a91..0000000 Binary files a/lesson29-BERT/self_attention/__pycache__/seq_self_attention.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/self_attention/__pycache__/seq_weighted_attention.cpython-36.pyc b/lesson29-BERT/self_attention/__pycache__/seq_weighted_attention.cpython-36.pyc deleted file mode 100644 index 8e20330..0000000 Binary files a/lesson29-BERT/self_attention/__pycache__/seq_weighted_attention.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/transformer/__pycache__/__init__.cpython-36.pyc b/lesson29-BERT/transformer/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index 736c470..0000000 Binary files a/lesson29-BERT/transformer/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/transformer/__pycache__/gelu.cpython-36.pyc b/lesson29-BERT/transformer/__pycache__/gelu.cpython-36.pyc deleted file mode 100644 index ad42e64..0000000 Binary files a/lesson29-BERT/transformer/__pycache__/gelu.cpython-36.pyc and /dev/null differ diff --git a/lesson29-BERT/transformer/__pycache__/transformer.cpython-36.pyc b/lesson29-BERT/transformer/__pycache__/transformer.cpython-36.pyc deleted file mode 100644 index a503a6d..0000000 Binary files a/lesson29-BERT/transformer/__pycache__/transformer.cpython-36.pyc and /dev/null differ diff --git a/lesson30-GCN/data/ind.citeseer.allx b/lesson30-GCN/data/ind.citeseer.allx deleted file mode 100644 index 5920910..0000000 Binary files a/lesson30-GCN/data/ind.citeseer.allx and /dev/null differ diff --git a/lesson30-GCN/data/ind.citeseer.ally b/lesson30-GCN/data/ind.citeseer.ally deleted file mode 100644 index 7503f81..0000000 Binary files a/lesson30-GCN/data/ind.citeseer.ally and /dev/null differ diff --git a/lesson30-GCN/data/ind.citeseer.graph b/lesson30-GCN/data/ind.citeseer.graph deleted file mode 100644 index a01dca6..0000000 Binary files a/lesson30-GCN/data/ind.citeseer.graph and /dev/null differ diff --git a/lesson30-GCN/data/ind.citeseer.test.index b/lesson30-GCN/data/ind.citeseer.test.index deleted file mode 100644 index 62d9e3d..0000000 --- a/lesson30-GCN/data/ind.citeseer.test.index +++ /dev/null @@ -1,1000 +0,0 @@ -2488 -2644 -3261 -2804 -3176 -2432 -3310 -2410 -2812 -2520 -2994 -3282 -2680 -2848 -2670 -3005 -2977 -2592 -2967 -2461 -3184 -2852 -2768 -2905 -2851 -3129 -3164 -2438 -2793 -2763 -2528 -2954 -2347 -2640 -3265 -2874 -2446 -2856 -3149 -2374 -3097 -3301 -2664 -2418 -2655 -2464 -2596 -3262 -3278 -2320 -2612 -2614 -2550 -2626 -2772 -3007 -2733 -2516 -2476 -2798 -2561 -2839 -2685 -2391 -2705 -3098 -2754 -3251 -2767 -2630 -2727 -2513 -2701 -3264 -2792 -2821 -3260 -2462 -3307 -2639 -2900 -3060 -2672 -3116 -2731 -3316 -2386 -2425 -2518 -3151 -2586 -2797 -2479 -3117 -2580 -3182 -2459 -2508 -3052 -3230 -3215 -2803 -2969 -2562 -2398 -3325 -2343 -3030 -2414 -2776 -2383 -3173 -2850 -2499 -3312 -2648 -2784 -2898 -3056 -2484 -3179 -3132 -2577 -2563 -2867 -3317 -2355 -3207 -3178 -2968 -3319 -2358 -2764 -3001 -2683 -3271 -2321 -2567 -2502 -3246 -2715 -3066 -2390 -2381 -3162 -2741 -2498 -2790 -3038 -3321 -2481 -3050 -3161 -3122 -2801 -2957 -3177 -2965 -2621 -3208 -2921 -2802 -2357 -2677 -2519 -2860 -2696 -2368 -3241 -2858 -2419 -2762 -2875 -3222 -3064 -2827 -3044 -2471 -3062 -2982 -2736 -2322 -2709 -2766 -2424 -2602 -2970 -2675 -3299 -2554 -2964 -2597 -2753 -2979 -2523 -2912 -2896 -2317 -3167 -2813 -2482 -2557 -3043 -3244 -2985 -2460 -2363 -3272 -3045 -3192 -2453 -2656 -2834 -2443 -3202 -2926 -2711 -2633 -2384 -2752 -3285 -2817 -2483 -2919 -2924 -2661 -2698 -2361 -2662 -2819 -3143 -2316 -3196 -2739 -2345 -2578 -2822 -3229 -2908 -2917 -2692 -3200 -2324 -2522 -3322 -2697 -3163 -3093 -3233 -2774 -2371 -2835 -2652 -2539 -2843 -3231 -2976 -2429 -2367 -3144 -2564 -3283 -3217 -3035 -2962 -2433 -2415 -2387 -3021 -2595 -2517 -2468 -3061 -2673 -2348 -3027 -2467 -3318 -2959 -3273 -2392 -2779 -2678 -3004 -2634 -2974 -3198 -2342 -2376 -3249 -2868 -2952 -2710 -2838 -2335 -2524 -2650 -3186 -2743 -2545 -2841 -2515 -2505 -3181 -2945 -2738 -2933 -3303 -2611 -3090 -2328 -3010 -3016 -2504 -2936 -3266 -3253 -2840 -3034 -2581 -2344 -2452 -2654 -3199 -3137 -2514 -2394 -2544 -2641 -2613 -2618 -2558 -2593 -2532 -2512 -2975 -3267 -2566 -2951 -3300 -2869 -2629 -2747 -3055 -2831 -3105 -3168 -3100 -2431 -2828 -2684 -3269 -2910 -2865 -2693 -2884 -3228 -2783 -3247 -2770 -3157 -2421 -2382 -2331 -3203 -3240 -2351 -3114 -2986 -2688 -2439 -2996 -3079 -3103 -3296 -2349 -2372 -3096 -2422 -2551 -3069 -2737 -3084 -3304 -3022 -2542 -3204 -2949 -2318 -2450 -3140 -2734 -2881 -2576 -3054 -3089 -3125 -2761 -3136 -3111 -2427 -2466 -3101 -3104 -3259 -2534 -2961 -3191 -3000 -3036 -2356 -2800 -3155 -3224 -2646 -2735 -3020 -2866 -2426 -2448 -3226 -3219 -2749 -3183 -2906 -2360 -2440 -2946 -2313 -2859 -2340 -3008 -2719 -3058 -2653 -3023 -2888 -3243 -2913 -3242 -3067 -2409 -3227 -2380 -2353 -2686 -2971 -2847 -2947 -2857 -3263 -3218 -2861 -3323 -2635 -2966 -2604 -2456 -2832 -2694 -3245 -3119 -2942 -3153 -2894 -2555 -3128 -2703 -2323 -2631 -2732 -2699 -2314 -2590 -3127 -2891 -2873 -2814 -2326 -3026 -3288 -3095 -2706 -2457 -2377 -2620 -2526 -2674 -3190 -2923 -3032 -2334 -3254 -2991 -3277 -2973 -2599 -2658 -2636 -2826 -3148 -2958 -3258 -2990 -3180 -2538 -2748 -2625 -2565 -3011 -3057 -2354 -3158 -2622 -3308 -2983 -2560 -3169 -3059 -2480 -3194 -3291 -3216 -2643 -3172 -2352 -2724 -2485 -2411 -2948 -2445 -2362 -2668 -3275 -3107 -2496 -2529 -2700 -2541 -3028 -2879 -2660 -3324 -2755 -2436 -3048 -2623 -2920 -3040 -2568 -3221 -3003 -3295 -2473 -3232 -3213 -2823 -2897 -2573 -2645 -3018 -3326 -2795 -2915 -3109 -3086 -2463 -3118 -2671 -2909 -2393 -2325 -3029 -2972 -3110 -2870 -3284 -2816 -2647 -2667 -2955 -2333 -2960 -2864 -2893 -2458 -2441 -2359 -2327 -3256 -3099 -3073 -3138 -2511 -2666 -2548 -2364 -2451 -2911 -3237 -3206 -3080 -3279 -2934 -2981 -2878 -3130 -2830 -3091 -2659 -2449 -3152 -2413 -2722 -2796 -3220 -2751 -2935 -3238 -2491 -2730 -2842 -3223 -2492 -3074 -3094 -2833 -2521 -2883 -3315 -2845 -2907 -3083 -2572 -3092 -2903 -2918 -3039 -3286 -2587 -3068 -2338 -3166 -3134 -2455 -2497 -2992 -2775 -2681 -2430 -2932 -2931 -2434 -3154 -3046 -2598 -2366 -3015 -3147 -2944 -2582 -3274 -2987 -2642 -2547 -2420 -2930 -2750 -2417 -2808 -3141 -2997 -2995 -2584 -2312 -3033 -3070 -3065 -2509 -3314 -2396 -2543 -2423 -3170 -2389 -3289 -2728 -2540 -2437 -2486 -2895 -3017 -2853 -2406 -2346 -2877 -2472 -3210 -2637 -2927 -2789 -2330 -3088 -3102 -2616 -3081 -2902 -3205 -3320 -3165 -2984 -3185 -2707 -3255 -2583 -2773 -2742 -3024 -2402 -2718 -2882 -2575 -3281 -2786 -2855 -3014 -2401 -2535 -2687 -2495 -3113 -2609 -2559 -2665 -2530 -3293 -2399 -2605 -2690 -3133 -2799 -2533 -2695 -2713 -2886 -2691 -2549 -3077 -3002 -3049 -3051 -3087 -2444 -3085 -3135 -2702 -3211 -3108 -2501 -2769 -3290 -2465 -3025 -3019 -2385 -2940 -2657 -2610 -2525 -2941 -3078 -2341 -2916 -2956 -2375 -2880 -3009 -2780 -2370 -2925 -2332 -3146 -2315 -2809 -3145 -3106 -2782 -2760 -2493 -2765 -2556 -2890 -2400 -2339 -3201 -2818 -3248 -3280 -2570 -2569 -2937 -3174 -2836 -2708 -2820 -3195 -2617 -3197 -2319 -2744 -2615 -2825 -2603 -2914 -2531 -3193 -2624 -2365 -2810 -3239 -3159 -2537 -2844 -2758 -2938 -3037 -2503 -3297 -2885 -2608 -2494 -2712 -2408 -2901 -2704 -2536 -2373 -2478 -2723 -3076 -2627 -2369 -2669 -3006 -2628 -2788 -3276 -2435 -3139 -3235 -2527 -2571 -2815 -2442 -2892 -2978 -2746 -3150 -2574 -2725 -3188 -2601 -2378 -3075 -2632 -2794 -3270 -3071 -2506 -3126 -3236 -3257 -2824 -2989 -2950 -2428 -2405 -3156 -2447 -2787 -2805 -2720 -2403 -2811 -2329 -2474 -2785 -2350 -2507 -2416 -3112 -2475 -2876 -2585 -2487 -3072 -3082 -2943 -2757 -2388 -2600 -3294 -2756 -3142 -3041 -2594 -2998 -3047 -2379 -2980 -2454 -2862 -3175 -2588 -3031 -3012 -2889 -2500 -2791 -2854 -2619 -2395 -2807 -2740 -2412 -3131 -3013 -2939 -2651 -2490 -2988 -2863 -3225 -2745 -2714 -3160 -3124 -2849 -2676 -2872 -3287 -3189 -2716 -3115 -2928 -2871 -2591 -2717 -2546 -2777 -3298 -2397 -3187 -2726 -2336 -3268 -2477 -2904 -2846 -3121 -2899 -2510 -2806 -2963 -3313 -2679 -3302 -2663 -3053 -2469 -2999 -3311 -2470 -2638 -3120 -3171 -2689 -2922 -2607 -2721 -2993 -2887 -2837 -2929 -2829 -3234 -2649 -2337 -2759 -2778 -2771 -2404 -2589 -3123 -3209 -2729 -3252 -2606 -2579 -2552 diff --git a/lesson30-GCN/data/ind.citeseer.tx b/lesson30-GCN/data/ind.citeseer.tx deleted file mode 100644 index b2aff18..0000000 Binary files a/lesson30-GCN/data/ind.citeseer.tx and /dev/null differ diff --git a/lesson30-GCN/data/ind.citeseer.ty b/lesson30-GCN/data/ind.citeseer.ty deleted file mode 100644 index 3795f79..0000000 Binary files a/lesson30-GCN/data/ind.citeseer.ty and /dev/null differ diff --git a/lesson30-GCN/data/ind.citeseer.x b/lesson30-GCN/data/ind.citeseer.x deleted file mode 100644 index f094104..0000000 Binary files a/lesson30-GCN/data/ind.citeseer.x and /dev/null differ diff --git a/lesson30-GCN/data/ind.citeseer.y b/lesson30-GCN/data/ind.citeseer.y deleted file mode 100644 index e857ac4..0000000 Binary files a/lesson30-GCN/data/ind.citeseer.y and /dev/null differ diff --git a/lesson30-GCN/data/ind.cora.allx b/lesson30-GCN/data/ind.cora.allx deleted file mode 100644 index 44d53b1..0000000 Binary files a/lesson30-GCN/data/ind.cora.allx and /dev/null differ diff --git a/lesson30-GCN/data/ind.cora.ally b/lesson30-GCN/data/ind.cora.ally deleted file mode 100644 index 04fbd0b..0000000 Binary files a/lesson30-GCN/data/ind.cora.ally and /dev/null differ diff --git a/lesson30-GCN/data/ind.cora.graph b/lesson30-GCN/data/ind.cora.graph deleted file mode 100644 index 4d3bf85..0000000 Binary files a/lesson30-GCN/data/ind.cora.graph and /dev/null differ diff --git a/lesson30-GCN/data/ind.cora.test.index b/lesson30-GCN/data/ind.cora.test.index deleted file mode 100644 index ded8092..0000000 --- a/lesson30-GCN/data/ind.cora.test.index +++ /dev/null @@ -1,1000 +0,0 @@ -2692 -2532 -2050 -1715 -2362 -2609 -2622 -1975 -2081 -1767 -2263 -1725 -2588 -2259 -2357 -1998 -2574 -2179 -2291 -2382 -1812 -1751 -2422 -1937 -2631 -2510 -2378 -2589 -2345 -1943 -1850 -2298 -1825 -2035 -2507 -2313 -1906 -1797 -2023 -2159 -2495 -1886 -2122 -2369 -2461 -1925 -2565 -1858 -2234 -2000 -1846 -2318 -1723 -2559 -2258 -1763 -1991 -1922 -2003 -2662 -2250 -2064 -2529 -1888 -2499 -2454 -2320 -2287 -2203 -2018 -2002 -2632 -2554 -2314 -2537 -1760 -2088 -2086 -2218 -2605 -1953 -2403 -1920 -2015 -2335 -2535 -1837 -2009 -1905 -2636 -1942 -2193 -2576 -2373 -1873 -2463 -2509 -1954 -2656 -2455 -2494 -2295 -2114 -2561 -2176 -2275 -2635 -2442 -2704 -2127 -2085 -2214 -2487 -1739 -2543 -1783 -2485 -2262 -2472 -2326 -1738 -2170 -2100 -2384 -2152 -2647 -2693 -2376 -1775 -1726 -2476 -2195 -1773 -1793 -2194 -2581 -1854 -2524 -1945 -1781 -1987 -2599 -1744 -2225 -2300 -1928 -2042 -2202 -1958 -1816 -1916 -2679 -2190 -1733 -2034 -2643 -2177 -1883 -1917 -1996 -2491 -2268 -2231 -2471 -1919 -1909 -2012 -2522 -1865 -2466 -2469 -2087 -2584 -2563 -1924 -2143 -1736 -1966 -2533 -2490 -2630 -1973 -2568 -1978 -2664 -2633 -2312 -2178 -1754 -2307 -2480 -1960 -1742 -1962 -2160 -2070 -2553 -2433 -1768 -2659 -2379 -2271 -1776 -2153 -1877 -2027 -2028 -2155 -2196 -2483 -2026 -2158 -2407 -1821 -2131 -2676 -2277 -2489 -2424 -1963 -1808 -1859 -2597 -2548 -2368 -1817 -2405 -2413 -2603 -2350 -2118 -2329 -1969 -2577 -2475 -2467 -2425 -1769 -2092 -2044 -2586 -2608 -1983 -2109 -2649 -1964 -2144 -1902 -2411 -2508 -2360 -1721 -2005 -2014 -2308 -2646 -1949 -1830 -2212 -2596 -1832 -1735 -1866 -2695 -1941 -2546 -2498 -2686 -2665 -1784 -2613 -1970 -2021 -2211 -2516 -2185 -2479 -2699 -2150 -1990 -2063 -2075 -1979 -2094 -1787 -2571 -2690 -1926 -2341 -2566 -1957 -1709 -1955 -2570 -2387 -1811 -2025 -2447 -2696 -2052 -2366 -1857 -2273 -2245 -2672 -2133 -2421 -1929 -2125 -2319 -2641 -2167 -2418 -1765 -1761 -1828 -2188 -1972 -1997 -2419 -2289 -2296 -2587 -2051 -2440 -2053 -2191 -1923 -2164 -1861 -2339 -2333 -2523 -2670 -2121 -1921 -1724 -2253 -2374 -1940 -2545 -2301 -2244 -2156 -1849 -2551 -2011 -2279 -2572 -1757 -2400 -2569 -2072 -2526 -2173 -2069 -2036 -1819 -1734 -1880 -2137 -2408 -2226 -2604 -1771 -2698 -2187 -2060 -1756 -2201 -2066 -2439 -1844 -1772 -2383 -2398 -1708 -1992 -1959 -1794 -2426 -2702 -2444 -1944 -1829 -2660 -2497 -2607 -2343 -1730 -2624 -1790 -1935 -1967 -2401 -2255 -2355 -2348 -1931 -2183 -2161 -2701 -1948 -2501 -2192 -2404 -2209 -2331 -1810 -2363 -2334 -1887 -2393 -2557 -1719 -1732 -1986 -2037 -2056 -1867 -2126 -1932 -2117 -1807 -1801 -1743 -2041 -1843 -2388 -2221 -1833 -2677 -1778 -2661 -2306 -2394 -2106 -2430 -2371 -2606 -2353 -2269 -2317 -2645 -2372 -2550 -2043 -1968 -2165 -2310 -1985 -2446 -1982 -2377 -2207 -1818 -1913 -1766 -1722 -1894 -2020 -1881 -2621 -2409 -2261 -2458 -2096 -1712 -2594 -2293 -2048 -2359 -1839 -2392 -2254 -1911 -2101 -2367 -1889 -1753 -2555 -2246 -2264 -2010 -2336 -2651 -2017 -2140 -1842 -2019 -1890 -2525 -2134 -2492 -2652 -2040 -2145 -2575 -2166 -1999 -2434 -1711 -2276 -2450 -2389 -2669 -2595 -1814 -2039 -2502 -1896 -2168 -2344 -2637 -2031 -1977 -2380 -1936 -2047 -2460 -2102 -1745 -2650 -2046 -2514 -1980 -2352 -2113 -1713 -2058 -2558 -1718 -1864 -1876 -2338 -1879 -1891 -2186 -2451 -2181 -2638 -2644 -2103 -2591 -2266 -2468 -1869 -2582 -2674 -2361 -2462 -1748 -2215 -2615 -2236 -2248 -2493 -2342 -2449 -2274 -1824 -1852 -1870 -2441 -2356 -1835 -2694 -2602 -2685 -1893 -2544 -2536 -1994 -1853 -1838 -1786 -1930 -2539 -1892 -2265 -2618 -2486 -2583 -2061 -1796 -1806 -2084 -1933 -2095 -2136 -2078 -1884 -2438 -2286 -2138 -1750 -2184 -1799 -2278 -2410 -2642 -2435 -1956 -2399 -1774 -2129 -1898 -1823 -1938 -2299 -1862 -2420 -2673 -1984 -2204 -1717 -2074 -2213 -2436 -2297 -2592 -2667 -2703 -2511 -1779 -1782 -2625 -2365 -2315 -2381 -1788 -1714 -2302 -1927 -2325 -2506 -2169 -2328 -2629 -2128 -2655 -2282 -2073 -2395 -2247 -2521 -2260 -1868 -1988 -2324 -2705 -2541 -1731 -2681 -2707 -2465 -1785 -2149 -2045 -2505 -2611 -2217 -2180 -1904 -2453 -2484 -1871 -2309 -2349 -2482 -2004 -1965 -2406 -2162 -1805 -2654 -2007 -1947 -1981 -2112 -2141 -1720 -1758 -2080 -2330 -2030 -2432 -2089 -2547 -1820 -1815 -2675 -1840 -2658 -2370 -2251 -1908 -2029 -2068 -2513 -2549 -2267 -2580 -2327 -2351 -2111 -2022 -2321 -2614 -2252 -2104 -1822 -2552 -2243 -1798 -2396 -2663 -2564 -2148 -2562 -2684 -2001 -2151 -2706 -2240 -2474 -2303 -2634 -2680 -2055 -2090 -2503 -2347 -2402 -2238 -1950 -2054 -2016 -1872 -2233 -1710 -2032 -2540 -2628 -1795 -2616 -1903 -2531 -2567 -1946 -1897 -2222 -2227 -2627 -1856 -2464 -2241 -2481 -2130 -2311 -2083 -2223 -2284 -2235 -2097 -1752 -2515 -2527 -2385 -2189 -2283 -2182 -2079 -2375 -2174 -2437 -1993 -2517 -2443 -2224 -2648 -2171 -2290 -2542 -2038 -1855 -1831 -1759 -1848 -2445 -1827 -2429 -2205 -2598 -2657 -1728 -2065 -1918 -2427 -2573 -2620 -2292 -1777 -2008 -1875 -2288 -2256 -2033 -2470 -2585 -2610 -2082 -2230 -1915 -1847 -2337 -2512 -2386 -2006 -2653 -2346 -1951 -2110 -2639 -2520 -1939 -2683 -2139 -2220 -1910 -2237 -1900 -1836 -2197 -1716 -1860 -2077 -2519 -2538 -2323 -1914 -1971 -1845 -2132 -1802 -1907 -2640 -2496 -2281 -2198 -2416 -2285 -1755 -2431 -2071 -2249 -2123 -1727 -2459 -2304 -2199 -1791 -1809 -1780 -2210 -2417 -1874 -1878 -2116 -1961 -1863 -2579 -2477 -2228 -2332 -2578 -2457 -2024 -1934 -2316 -1841 -1764 -1737 -2322 -2239 -2294 -1729 -2488 -1974 -2473 -2098 -2612 -1834 -2340 -2423 -2175 -2280 -2617 -2208 -2560 -1741 -2600 -2059 -1747 -2242 -2700 -2232 -2057 -2147 -2682 -1792 -1826 -2120 -1895 -2364 -2163 -1851 -2391 -2414 -2452 -1803 -1989 -2623 -2200 -2528 -2415 -1804 -2146 -2619 -2687 -1762 -2172 -2270 -2678 -2593 -2448 -1882 -2257 -2500 -1899 -2478 -2412 -2107 -1746 -2428 -2115 -1800 -1901 -2397 -2530 -1912 -2108 -2206 -2091 -1740 -2219 -1976 -2099 -2142 -2671 -2668 -2216 -2272 -2229 -2666 -2456 -2534 -2697 -2688 -2062 -2691 -2689 -2154 -2590 -2626 -2390 -1813 -2067 -1952 -2518 -2358 -1789 -2076 -2049 -2119 -2013 -2124 -2556 -2105 -2093 -1885 -2305 -2354 -2135 -2601 -1770 -1995 -2504 -1749 -2157 diff --git a/lesson30-GCN/data/ind.cora.tx b/lesson30-GCN/data/ind.cora.tx deleted file mode 100644 index 6e856d7..0000000 Binary files a/lesson30-GCN/data/ind.cora.tx and /dev/null differ diff --git a/lesson30-GCN/data/ind.cora.ty b/lesson30-GCN/data/ind.cora.ty deleted file mode 100644 index da1734a..0000000 Binary files a/lesson30-GCN/data/ind.cora.ty and /dev/null differ diff --git a/lesson30-GCN/data/ind.cora.x b/lesson30-GCN/data/ind.cora.x deleted file mode 100644 index c4a91d0..0000000 Binary files a/lesson30-GCN/data/ind.cora.x and /dev/null differ diff --git a/lesson30-GCN/data/ind.cora.y b/lesson30-GCN/data/ind.cora.y deleted file mode 100644 index 58e30ef..0000000 Binary files a/lesson30-GCN/data/ind.cora.y and /dev/null differ diff --git a/lesson30-GCN/data/ind.pubmed.allx b/lesson30-GCN/data/ind.pubmed.allx deleted file mode 100644 index 3b86bcc..0000000 Binary files a/lesson30-GCN/data/ind.pubmed.allx and /dev/null differ diff --git a/lesson30-GCN/data/ind.pubmed.ally b/lesson30-GCN/data/ind.pubmed.ally deleted file mode 100644 index 4c8bcdc..0000000 Binary files a/lesson30-GCN/data/ind.pubmed.ally and /dev/null differ diff --git a/lesson30-GCN/data/ind.pubmed.graph b/lesson30-GCN/data/ind.pubmed.graph deleted file mode 100644 index 76eb87e..0000000 Binary files a/lesson30-GCN/data/ind.pubmed.graph and /dev/null differ diff --git a/lesson30-GCN/data/ind.pubmed.test.index b/lesson30-GCN/data/ind.pubmed.test.index deleted file mode 100644 index 41f6bef..0000000 --- a/lesson30-GCN/data/ind.pubmed.test.index +++ /dev/null @@ -1,1000 +0,0 @@ -18747 -19392 -19181 -18843 -19221 -18962 -19560 -19097 -18966 -19014 -18756 -19313 -19000 -19569 -19359 -18854 -18970 -19073 -19661 -19180 -19377 -18750 -19401 -18788 -19224 -19447 -19017 -19241 -18890 -18908 -18965 -19001 -18849 -19641 -18852 -19222 -19172 -18762 -19156 -19162 -18856 -18763 -19318 -18826 -19712 -19192 -19695 -19030 -19523 -19249 -19079 -19232 -19455 -18743 -18800 -19071 -18885 -19593 -19394 -19390 -18832 -19445 -18838 -19632 -19548 -19546 -18825 -19498 -19266 -19117 -19595 -19252 -18730 -18913 -18809 -19452 -19520 -19274 -19555 -19388 -18919 -19099 -19637 -19403 -18720 -19526 -18905 -19451 -19408 -18923 -18794 -19322 -19431 -18912 -18841 -19239 -19125 -19258 -19565 -18898 -19482 -19029 -18778 -19096 -19684 -19552 -18765 -19361 -19171 -19367 -19623 -19402 -19327 -19118 -18888 -18726 -19510 -18831 -19490 -19576 -19050 -18729 -18896 -19246 -19012 -18862 -18873 -19193 -19693 -19474 -18953 -19115 -19182 -19269 -19116 -18837 -18872 -19007 -19212 -18798 -19102 -18772 -19660 -19511 -18914 -18886 -19672 -19360 -19213 -18810 -19420 -19512 -18719 -19432 -19350 -19127 -18782 -19587 -18924 -19488 -18781 -19340 -19190 -19383 -19094 -18835 -19487 -19230 -18791 -18882 -18937 -18928 -18755 -18802 -19516 -18795 -18786 -19273 -19349 -19398 -19626 -19130 -19351 -19489 -19446 -18959 -19025 -18792 -18878 -19304 -19629 -19061 -18785 -19194 -19179 -19210 -19417 -19583 -19415 -19443 -18739 -19662 -18904 -18910 -18901 -18960 -18722 -18827 -19290 -18842 -19389 -19344 -18961 -19098 -19147 -19334 -19358 -18829 -18984 -18931 -18742 -19320 -19111 -19196 -18887 -18991 -19469 -18990 -18876 -19261 -19270 -19522 -19088 -19284 -19646 -19493 -19225 -19615 -19449 -19043 -19674 -19391 -18918 -19155 -19110 -18815 -19131 -18834 -19715 -19603 -19688 -19133 -19053 -19166 -19066 -18893 -18757 -19582 -19282 -19257 -18869 -19467 -18954 -19371 -19151 -19462 -19598 -19653 -19187 -19624 -19564 -19534 -19581 -19478 -18985 -18746 -19342 -18777 -19696 -18824 -19138 -18728 -19643 -19199 -18731 -19168 -18948 -19216 -19697 -19347 -18808 -18725 -19134 -18847 -18828 -18996 -19106 -19485 -18917 -18911 -18776 -19203 -19158 -18895 -19165 -19382 -18780 -18836 -19373 -19659 -18947 -19375 -19299 -18761 -19366 -18754 -19248 -19416 -19658 -19638 -19034 -19281 -18844 -18922 -19491 -19272 -19341 -19068 -19332 -19559 -19293 -18804 -18933 -18935 -19405 -18936 -18945 -18943 -18818 -18797 -19570 -19464 -19428 -19093 -19433 -18986 -19161 -19255 -19157 -19046 -19292 -19434 -19298 -18724 -19410 -19694 -19214 -19640 -19189 -18963 -19218 -19585 -19041 -19550 -19123 -19620 -19376 -19561 -18944 -19706 -19056 -19283 -18741 -19319 -19144 -19542 -18821 -19404 -19080 -19303 -18793 -19306 -19678 -19435 -19519 -19566 -19278 -18946 -19536 -19020 -19057 -19198 -19333 -19649 -19699 -19399 -19654 -19136 -19465 -19321 -19577 -18907 -19665 -19386 -19596 -19247 -19473 -19568 -19355 -18925 -19586 -18982 -19616 -19495 -19612 -19023 -19438 -18817 -19692 -19295 -19414 -19676 -19472 -19107 -19062 -19035 -18883 -19409 -19052 -19606 -19091 -19651 -19475 -19413 -18796 -19369 -19639 -19701 -19461 -19645 -19251 -19063 -19679 -19545 -19081 -19363 -18995 -19549 -18790 -18855 -18833 -18899 -19395 -18717 -19647 -18768 -19103 -19245 -18819 -18779 -19656 -19076 -18745 -18971 -19197 -19711 -19074 -19128 -19466 -19139 -19309 -19324 -18814 -19092 -19627 -19060 -18806 -18929 -18737 -18942 -18906 -18858 -19456 -19253 -19716 -19104 -19667 -19574 -18903 -19237 -18864 -19556 -19364 -18952 -19008 -19323 -19700 -19170 -19267 -19345 -19238 -18909 -18892 -19109 -19704 -18902 -19275 -19680 -18723 -19242 -19112 -19169 -18956 -19343 -19650 -19541 -19698 -19521 -19087 -18976 -19038 -18775 -18968 -19671 -19412 -19407 -19573 -19027 -18813 -19357 -19460 -19673 -19481 -19036 -19614 -18787 -19195 -18732 -18884 -19613 -19657 -19575 -19226 -19589 -19234 -19617 -19707 -19484 -18740 -19424 -18784 -19419 -19159 -18865 -19105 -19315 -19480 -19664 -19378 -18803 -19605 -18870 -19042 -19426 -18848 -19223 -19509 -19532 -18752 -19691 -18718 -19209 -19362 -19090 -19492 -19567 -19687 -19018 -18830 -19530 -19554 -19119 -19442 -19558 -19527 -19427 -19291 -19543 -19422 -19142 -18897 -18950 -19425 -19002 -19588 -18978 -19551 -18930 -18736 -19101 -19215 -19150 -19263 -18949 -18974 -18759 -19335 -19200 -19129 -19328 -19437 -18988 -19429 -19368 -19406 -19049 -18811 -19296 -19256 -19385 -19602 -18770 -19337 -19580 -19476 -19045 -19132 -19089 -19120 -19265 -19483 -18767 -19227 -18934 -19069 -18820 -19006 -19459 -18927 -19037 -19280 -19441 -18823 -19015 -19114 -19618 -18957 -19176 -18853 -19648 -19201 -19444 -19279 -18751 -19302 -19505 -18733 -19601 -19533 -18863 -19708 -19387 -19346 -19152 -19206 -18851 -19338 -19681 -19380 -19055 -18766 -19085 -19591 -19547 -18958 -19146 -18840 -19051 -19021 -19207 -19235 -19086 -18979 -19300 -18939 -19100 -19619 -19287 -18980 -19277 -19326 -19108 -18920 -19625 -19374 -19078 -18734 -19634 -19339 -18877 -19423 -19652 -19683 -19044 -18983 -19330 -19529 -19714 -19468 -19075 -19540 -18839 -19022 -19286 -19537 -19175 -19463 -19167 -19705 -19562 -19244 -19486 -19611 -18801 -19178 -19590 -18846 -19450 -19205 -19381 -18941 -19670 -19185 -19504 -19633 -18997 -19113 -19397 -19636 -19709 -19289 -19264 -19353 -19584 -19126 -18938 -19669 -18964 -19276 -18774 -19173 -19231 -18973 -18769 -19064 -19040 -19668 -18738 -19082 -19655 -19236 -19352 -19609 -19628 -18951 -19384 -19122 -18875 -18992 -18753 -19379 -19254 -19301 -19506 -19135 -19010 -19682 -19400 -19579 -19316 -19553 -19208 -19635 -19644 -18891 -19024 -18989 -19250 -18850 -19317 -18915 -19607 -18799 -18881 -19479 -19031 -19365 -19164 -18744 -18760 -19502 -19058 -19517 -18735 -19448 -19243 -19453 -19285 -18857 -19439 -19016 -18975 -19503 -18998 -18981 -19186 -18994 -19240 -19631 -19070 -19174 -18900 -19065 -19220 -19229 -18880 -19308 -19372 -19496 -18771 -19325 -19538 -19033 -18874 -19077 -19211 -18764 -19458 -19571 -19121 -19019 -19059 -19497 -18969 -19666 -19297 -19219 -19622 -19184 -18977 -19702 -19539 -19329 -19095 -19675 -18972 -19514 -19703 -19188 -18866 -18812 -19314 -18822 -18845 -19494 -19411 -18916 -19686 -18967 -19294 -19143 -19204 -18805 -19689 -19233 -18758 -18748 -19011 -19685 -19336 -19608 -19454 -19124 -18868 -18807 -19544 -19621 -19228 -19154 -19141 -19145 -19153 -18860 -19163 -19393 -19268 -19160 -19305 -19259 -19471 -19524 -18783 -19396 -18894 -19430 -19690 -19348 -19597 -19592 -19677 -18889 -19331 -18773 -19137 -19009 -18932 -19599 -18816 -19054 -19067 -19477 -19191 -18921 -18940 -19578 -19183 -19004 -19072 -19710 -19005 -19610 -18955 -19457 -19148 -18859 -18993 -19642 -19047 -19418 -19535 -19600 -19312 -19039 -19028 -18879 -19003 -19026 -19013 -19149 -19177 -19217 -18987 -19354 -19525 -19202 -19084 -19032 -18749 -18867 -19048 -18999 -19260 -19630 -18727 -19356 -19083 -18926 -18789 -19370 -18861 -19311 -19557 -19531 -19436 -19140 -19310 -19501 -18721 -19604 -19713 -19262 -19563 -19507 -19440 -19572 -19513 -19515 -19518 -19421 -19470 -19499 -19663 -19508 -18871 -19528 -19500 -19307 -19288 -19594 -19271 diff --git a/lesson30-GCN/data/ind.pubmed.tx b/lesson30-GCN/data/ind.pubmed.tx deleted file mode 100644 index eee4f3c..0000000 Binary files a/lesson30-GCN/data/ind.pubmed.tx and /dev/null differ diff --git a/lesson30-GCN/data/ind.pubmed.ty b/lesson30-GCN/data/ind.pubmed.ty deleted file mode 100644 index 225a0bb..0000000 Binary files a/lesson30-GCN/data/ind.pubmed.ty and /dev/null differ diff --git a/lesson30-GCN/data/ind.pubmed.x b/lesson30-GCN/data/ind.pubmed.x deleted file mode 100644 index 16c0eca..0000000 Binary files a/lesson30-GCN/data/ind.pubmed.x and /dev/null differ diff --git a/lesson30-GCN/data/ind.pubmed.y b/lesson30-GCN/data/ind.pubmed.y deleted file mode 100644 index e866705..0000000 Binary files a/lesson30-GCN/data/ind.pubmed.y and /dev/null differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TF.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TF.png" new file mode 100644 index 0000000..c2b9c1e Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TF.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" new file mode 100644 index 0000000..5e54483 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/0-\350\257\276\347\250\213\344\273\213\347\273\215/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -0,0 +1,7 @@ +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/Readme.md" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/Readme.md" index 8d672d6..ce0a726 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/Readme.md" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/Readme.md" @@ -1,5 +1,15 @@ # 深度å¦ä¹ 与TensorFlow2入门实战 +## 安装命令 + +请先安装Anaconda, CUDA 10.0, cuDNN。 + +```python +pip install -U tensorflow-gpu numpy matplotlib pillow pandas -i https://pypi.tuna.tsinghua.edu.cn/simple +``` + +## 课程链接 + 视频教程链接:[深度å¦ä¹ 与TensorFlow2入门实战](https://study.163.com/course/courseMain.htm?share=2&shareId=480000001847407&courseId=1209092816&_trace_c_p_k2_=10515f5942ba46b5a4ec1c30a46b0269) - \ No newline at end of file + diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\255\224\347\226\221\347\276\244-926107229.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\255\224\347\226\221\347\276\244-926107229.png" deleted file mode 100644 index e503df4..0000000 Binary files "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\347\255\224\347\226\221\347\276\244-926107229.png" and /dev/null differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" index a843ce6..5e54483 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson01-\345\210\235\350\247\201TensorFlow2.0/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -1 +1,7 @@ -´ðÒÉQQȺ-926107229 \ No newline at end of file +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/test.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/test.py" index a81949a..2a6644a 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/test.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/test.py" @@ -1,8 +1,10 @@ -import tensorflow as tf import os - os.environ['TF_CPP_MIN_LOG_LEVEL']='2' +import tensorflow as tf + + + a = tf.constant(1.) b = tf.constant(2.) print(a+b) diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207-Win10.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207-Win10.pdf" deleted file mode 100755 index feab135..0000000 Binary files "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207-Win10.pdf" and /dev/null differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\256\211\350\243\205-\346\236\201\347\256\200\347\211\210.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\256\211\350\243\205-\346\236\201\347\256\200\347\211\210.pdf" new file mode 100644 index 0000000..25dddd8 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\256\211\350\243\205-\346\236\201\347\256\200\347\211\210.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\256\211\350\243\205-\346\240\207\345\207\206\347\211\210.pdf" old mode 100755 new mode 100644 similarity index 67% rename from "\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.pdf" rename to "\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\256\211\350\243\205-\346\240\207\345\207\206\347\211\210.pdf" index 4142c11..04cb6b5 Binary files "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207.pdf" and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\345\274\200\345\217\221\347\216\257\345\242\203\345\256\211\350\243\205-\346\240\207\345\207\206\347\211\210.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\255\224\347\226\221\347\276\244-926107229.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\255\224\347\226\221\347\276\244-926107229.png" deleted file mode 100644 index e503df4..0000000 Binary files "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\347\255\224\347\226\221\347\276\244-926107229.png" and /dev/null differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" index a843ce6..5e54483 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson02-\345\274\200\345\217\221\347\216\257\345\242\203\345\207\206\345\244\207/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -1 +1,7 @@ -´ðÒÉQQȺ-926107229 \ No newline at end of file +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" new file mode 100644 index 0000000..5e54483 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson03-\345\233\236\345\275\222\351\227\256\351\242\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -0,0 +1,7 @@ +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\255\224\347\226\221\347\276\244-926107229.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\255\224\347\226\221\347\276\244-926107229.png" deleted file mode 100644 index e503df4..0000000 Binary files "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\347\255\224\347\226\221\347\276\244-926107229.png" and /dev/null differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" index a843ce6..5e54483 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson04-\345\233\236\345\275\222\351\227\256\351\242\230\345\256\236\346\210\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -1 +1,7 @@ -´ðÒÉQQȺ-926107229 \ No newline at end of file +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" new file mode 100644 index 0000000..5e54483 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson05-\346\211\213\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -0,0 +1,7 @@ +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/main.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/main.py" index 85ba561..3eaeb98 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/main.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/main.py" @@ -1,10 +1,11 @@ import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf from tensorflow import keras from tensorflow.keras import layers, optimizers, datasets -os.environ['TF_CPP_MIN_LOG_LEVEL']='2' (x, y), (x_val, y_val) = datasets.mnist.load_data() x = tf.convert_to_tensor(x, dtype=tf.float32) / 255. diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" new file mode 100644 index 0000000..5e54483 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson06-\346\211\213\345\206\231\346\225\260\345\255\227\350\257\206\345\210\253\345\210\235\344\275\223\351\252\214/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -0,0 +1,7 @@ +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" new file mode 100644 index 0000000..5e54483 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson07-\346\225\260\346\215\256\347\261\273\345\236\213/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -0,0 +1,7 @@ +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\347\211\210\346\235\203\345\243\260\346\230\216.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\347\211\210\346\235\203\345\243\260\346\230\216.png" new file mode 100644 index 0000000..f493c78 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\347\211\210\346\235\203\345\243\260\346\230\216.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\347\255\224\347\226\221\347\276\244-441082251.png" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\347\255\224\347\226\221\347\276\244-441082251.png" new file mode 100644 index 0000000..baf57bd Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\347\255\224\347\226\221\347\276\244-441082251.png" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" new file mode 100644 index 0000000..5e54483 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson08-\345\210\233\345\273\272Tensor/\350\257\267\345\255\246\345\221\230\345\212\241\345\277\205\345\212\240\347\276\244\347\255\224\347\226\221\357\274\201\357\274\201\357\274\201.txt" @@ -0,0 +1,7 @@ +´ðÒÉQQȺ-¡¾441082251¡¿ + +ÇëÊäÈë¿Î³Ì¶©µ¥ºÅ¡£ + +¶©µ¥ºÅ²éѯ·½·¨£º +1.APP¶Ë¡£¡¾Õ˺š¿->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ +2.ÍøÒ³¶Ë¡£ÓÒÉϽÇÍ·Ïñ´¦Êó±êÐü¸¡->¡¾ÎҵĶ©µ¥¡¿->ÕÒµ½¶ÔÓ¦¿Î³ÌµÄ¶©µ¥ºÅ \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson24-\350\257\257\345\267\256\350\256\241\347\256\227/\350\257\257\345\267\256\350\256\241\347\256\227.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson24-\350\257\257\345\267\256\350\256\241\347\256\227/\350\257\257\345\267\256\350\256\241\347\256\227.pdf" index bf4d3fd..4f8a107 100755 Binary files "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson24-\350\257\257\345\267\256\350\256\241\347\256\227/\350\257\257\345\267\256\350\256\241\347\256\227.pdf" and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson24-\350\257\257\345\267\256\350\256\241\347\256\227/\350\257\257\345\267\256\350\256\241\347\256\227.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson25-\346\242\257\345\272\246\350\256\241\347\256\227/2.\345\270\270\350\247\201\345\207\275\346\225\260\347\232\204\346\242\257\345\272\246.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson25-\346\242\257\345\272\246\350\256\241\347\256\227/2.\345\270\270\350\247\201\345\207\275\346\225\260\347\232\204\346\242\257\345\272\246.pdf" new file mode 100644 index 0000000..b1313fa Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson25-\346\242\257\345\272\246\350\256\241\347\256\227/2.\345\270\270\350\247\201\345\207\275\346\225\260\347\232\204\346\242\257\345\272\246.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson27-\344\271\246\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230\357\274\210\345\261\202\357\274\211-\345\256\236\346\210\230/fashionmnist_layer.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson27-\344\271\246\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230\357\274\210\345\261\202\357\274\211-\345\256\236\346\210\230/fashionmnist_layer.py" index c84a9e4..656e47b 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson27-\344\271\246\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230\357\274\210\345\261\202\357\274\211-\345\256\236\346\210\230/fashionmnist_layer.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson27-\344\271\246\345\206\231\346\225\260\345\255\227\351\227\256\351\242\230\357\274\210\345\261\202\357\274\211-\345\256\236\346\210\230/fashionmnist_layer.py" @@ -1,10 +1,11 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' + import tensorflow as tf from tensorflow import keras from tensorflow.keras import datasets, layers, optimizers, Sequential, metrics -import os - -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +assert tf.__version__.startswith('2.') def preprocess(x, y): @@ -16,6 +17,7 @@ def preprocess(x, y): (x, y), (x_test, y_test) = datasets.fashion_mnist.load_data() print(x.shape, y.shape) + batchsz = 128 db = tf.data.Dataset.from_tensor_slices((x,y)) diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson28-\345\217\257\350\247\206\345\214\226/main.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson28-\345\217\257\350\247\206\345\214\226/main.py" index 8a47a42..5ca4ff1 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson28-\345\217\257\350\247\206\345\214\226/main.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson28-\345\217\257\350\247\206\345\214\226/main.py" @@ -1,9 +1,14 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf from tensorflow.keras import datasets, layers, optimizers, Sequential, metrics import datetime from matplotlib import pyplot as plt import io +assert tf.__version__.startswith('2.') + def preprocess(x, y): x = tf.cast(x, dtype=tf.float32) / 255. diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson30-Keras\351\253\230\345\261\202API/layer_model.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson30-Keras\351\253\230\345\261\202API/layer_model.py" index 9ca380d..98073f2 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson30-Keras\351\253\230\345\261\202API/layer_model.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson30-Keras\351\253\230\345\261\202API/layer_model.py" @@ -42,8 +42,8 @@ class MyDense(layers.Layer): def __init__(self, inp_dim, outp_dim): super(MyDense, self).__init__() - self.kernel = self.add_variable('w', [inp_dim, outp_dim]) - self.bias = self.add_variable('b', [outp_dim]) + self.kernel = self.add_weight('w', [inp_dim, outp_dim]) + self.bias = self.add_weight('b', [outp_dim]) def call(self, inputs, training=None): diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson31-Keras\346\250\241\345\236\213\344\277\235\345\255\230\344\270\216\345\212\240\350\275\275/save_load_model.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson31-Keras\346\250\241\345\236\213\344\277\235\345\255\230\344\270\216\345\212\240\350\275\275/save_load_model.py" index ace20f9..8fab956 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson31-Keras\346\250\241\345\236\213\344\277\235\345\255\230\344\270\216\345\212\240\350\275\275/save_load_model.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson31-Keras\346\250\241\345\236\213\344\277\235\345\255\230\344\270\216\345\212\240\350\275\275/save_load_model.py" @@ -1,3 +1,6 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf from tensorflow.keras import datasets, layers, optimizers, Sequential, metrics diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson31-Keras\346\250\241\345\236\213\344\277\235\345\255\230\344\270\216\345\212\240\350\275\275/save_load_weight.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson31-Keras\346\250\241\345\236\213\344\277\235\345\255\230\344\270\216\345\212\240\350\275\275/save_load_weight.py" index f9c4eef..b752813 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson31-Keras\346\250\241\345\236\213\344\277\235\345\255\230\344\270\216\345\212\240\350\275\275/save_load_weight.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson31-Keras\346\250\241\345\236\213\344\277\235\345\255\230\344\270\216\345\212\240\350\275\275/save_load_weight.py" @@ -1,3 +1,6 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf from tensorflow.keras import datasets, layers, optimizers, Sequential, metrics diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson32-Keras\345\256\236\346\210\230/keras_train.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson32-Keras\345\256\236\346\210\230/keras_train.py" index f82e06b..d524e13 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson32-Keras\345\256\236\346\210\230/keras_train.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson32-Keras\345\256\236\346\210\230/keras_train.py" @@ -1,9 +1,10 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf from tensorflow.keras import datasets, layers, optimizers, Sequential, metrics from tensorflow import keras -import os -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' def preprocess(x, y): diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson37-Early Stopping, Dropout/dropout.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson37-Early Stopping, Dropout/dropout.py" index d378e2c..1658573 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson37-Early Stopping, Dropout/dropout.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson37-Early Stopping, Dropout/dropout.py" @@ -1,3 +1,6 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf from tensorflow.keras import datasets, layers, optimizers, Sequential, metrics diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson40-CIFAR\344\270\216VGG\345\256\236\346\210\230/cifar100_train.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson40-CIFAR\344\270\216VGG\345\256\236\346\210\230/cifar100_train.py" index f86318e..f962343 100755 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson40-CIFAR\344\270\216VGG\345\256\236\346\210\230/cifar100_train.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson40-CIFAR\344\270\216VGG\345\256\236\346\210\230/cifar100_train.py" @@ -1,8 +1,9 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf from tensorflow.keras import layers, optimizers, datasets, Sequential -import os -os.environ['TF_CPP_MIN_LOG_LEVEL']='2' tf.random.set_seed(2345) conv_layers = [ # 5 units of conv + max pooling diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson42-BatchNorm/BatchNorm.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson42-BatchNorm/BatchNorm.pdf" new file mode 100644 index 0000000..101e9ef Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson42-BatchNorm/BatchNorm.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson42-BatchNorm/main.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson42-BatchNorm/main.py" new file mode 100644 index 0000000..790a235 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson42-BatchNorm/main.py" @@ -0,0 +1,38 @@ +import tensorflow as tf + +from tensorflow import keras +from tensorflow.keras import layers, optimizers + + +# 2 images with 4x4 size, 3 channels +# we explicitly enforce the mean and stddev to N(1, 0.5) +x = tf.random.normal([2,4,4,3], mean=1.,stddev=0.5) + +net = layers.BatchNormalization(axis=-1, center=True, scale=True, + trainable=True) + +out = net(x) +print('forward in test mode:', net.variables) + + +out = net(x, training=True) +print('forward in train mode(1 step):', net.variables) + +for i in range(100): + out = net(x, training=True) +print('forward in train mode(100 steps):', net.variables) + + +optimizer = optimizers.SGD(lr=1e-2) +for i in range(10): + with tf.GradientTape() as tape: + out = net(x, training=True) + loss = tf.reduce_mean(tf.pow(out,2)) - 1 + + grads = tape.gradient(loss, net.trainable_variables) + optimizer.apply_gradients(zip(grads, net.trainable_variables)) +print('backward(10 steps):', net.variables) + + + + diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson43-ResNet/resnet.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson43-ResNet/resnet.py" index 537d486..3db2516 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson43-ResNet/resnet.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson43-ResNet/resnet.py" @@ -28,11 +28,11 @@ def call(self, inputs, training=None): # [b, h, w, c] out = self.conv1(inputs) - out = self.bn1(out) + out = self.bn1(out,training=training) out = self.relu(out) out = self.conv2(out) - out = self.bn2(out) + out = self.bn2(out,training=training) identity = self.downsample(inputs) @@ -69,12 +69,12 @@ def __init__(self, layer_dims, num_classes=100): # [2, 2, 2, 2] def call(self, inputs, training=None): - x = self.stem(inputs) + x = self.stem(inputs,training=training) - x = self.layer1(x) - x = self.layer2(x) - x = self.layer3(x) - x = self.layer4(x) + x = self.layer1(x,training=training) + x = self.layer2(x,training=training) + x = self.layer3(x,training=training) + x = self.layer4(x,training=training) # [b, c] x = self.avgpool(x) @@ -102,4 +102,4 @@ def resnet18(): def resnet34(): - return ResNet([3, 4, 6, 3]) \ No newline at end of file + return ResNet([3, 4, 6, 3]) diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson43-ResNet/resnet18_train.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson43-ResNet/resnet18_train.py" index 1f6dc57..a3e5471 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson43-ResNet/resnet18_train.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson43-ResNet/resnet18_train.py" @@ -1,9 +1,10 @@ -import tensorflow as tf -from tensorflow.keras import layers, optimizers, datasets, Sequential import os -from resnet import resnet18 - os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + +import tensorflow as tf +from tensorflow.keras import layers, optimizers, datasets, Sequential +from resnet import resnet18 + tf.random.set_seed(2345) @@ -48,7 +49,7 @@ def main(): with tf.GradientTape() as tape: # [b, 32, 32, 3] => [b, 100] - logits = model(x) + logits = model(x,training=True) # [b] => [b, 100] y_onehot = tf.one_hot(y, depth=100) # compute loss @@ -67,7 +68,7 @@ def main(): total_correct = 0 for x,y in test_db: - logits = model(x) + logits = model(x,training=False) prob = tf.nn.softmax(logits, axis=1) pred = tf.argmax(prob, axis=1) pred = tf.cast(pred, dtype=tf.int32) diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson45-RNN\345\256\236\346\210\230/sentiment_analysis_cell.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson45-RNN\345\256\236\346\210\230/sentiment_analysis_cell.py" index df2125a..da4e382 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson45-RNN\345\256\236\346\210\230/sentiment_analysis_cell.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson45-RNN\345\256\236\346\210\230/sentiment_analysis_cell.py" @@ -1,4 +1,6 @@ import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf import numpy as np from tensorflow import keras @@ -6,8 +8,7 @@ tf.random.set_seed(22) -np.random.seed(22) -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +np.random.seed(22) assert tf.__version__.startswith('2.') batchsz = 128 @@ -92,7 +93,7 @@ def main(): model = MyRNN(units) model.compile(optimizer = keras.optimizers.Adam(0.001), loss = tf.losses.BinaryCrossentropy(), - metrics=['accuracy']) + metrics=['accuracy'],experimental_run_tf_function=False) model.fit(db_train, epochs=epochs, validation_data=db_test) model.evaluate(db_test) diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson45-RNN\345\256\236\346\210\230/sentiment_analysis_layer.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson45-RNN\345\256\236\346\210\230/sentiment_analysis_layer.py" index 711fa16..0192e10 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson45-RNN\345\256\236\346\210\230/sentiment_analysis_layer.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson45-RNN\345\256\236\346\210\230/sentiment_analysis_layer.py" @@ -1,4 +1,6 @@ import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf import numpy as np from tensorflow import keras @@ -6,8 +8,7 @@ tf.random.set_seed(22) -np.random.seed(22) -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +np.random.seed(22) assert tf.__version__.startswith('2.') batchsz = 128 @@ -66,7 +67,7 @@ def call(self, inputs, training=None): x = self.embedding(x) # rnn cell compute # x: [b, 80, 100] => [b, 64] - x = self.rnn(x) + x = self.rnn(x,training=training) # out: [b, 64] => [b, 1] x = self.outlayer(x) @@ -80,6 +81,8 @@ def main(): epochs = 4 model = MyRNN(units) + # model.build(input_shape=(4,80)) + # model.summary() model.compile(optimizer = keras.optimizers.Adam(0.001), loss = tf.losses.BinaryCrossentropy(), metrics=['accuracy']) diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson46-LSTM/LSTM.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson46-LSTM/LSTM.pdf" new file mode 100644 index 0000000..509c3b5 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson46-LSTM/LSTM.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson46-LSTM/\346\242\257\345\272\246\345\274\245\346\225\243\344\270\216\346\242\257\345\272\246\347\210\206\347\202\270.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson46-LSTM/\346\242\257\345\272\246\345\274\245\346\225\243\344\270\216\346\242\257\345\272\246\347\210\206\347\202\270.pdf" new file mode 100644 index 0000000..3809d50 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson46-LSTM/\346\242\257\345\272\246\345\274\245\346\225\243\344\270\216\346\242\257\345\272\246\347\210\206\347\202\270.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/LSTM\345\256\236\346\210\230.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/LSTM\345\256\236\346\210\230.pdf" new file mode 100644 index 0000000..291cd4c Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/LSTM\345\256\236\346\210\230.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/gru_sentiment_analysis_cell.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/gru_sentiment_analysis_cell.py" new file mode 100644 index 0000000..53cf87c --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/gru_sentiment_analysis_cell.py" @@ -0,0 +1,114 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + +import tensorflow as tf +import numpy as np +from tensorflow import keras +from tensorflow.keras import layers + + +tf.random.set_seed(22) +np.random.seed(22) +assert tf.__version__.startswith('2.') + +batchsz = 128 + +# the most frequest words +total_words = 10000 +max_review_len = 80 +embedding_len = 100 +(x_train, y_train), (x_test, y_test) = keras.datasets.imdb.load_data(num_words=total_words) +# x_train:[b, 80] +# x_test: [b, 80] +x_train = keras.preprocessing.sequence.pad_sequences(x_train, maxlen=max_review_len) +x_test = keras.preprocessing.sequence.pad_sequences(x_test, maxlen=max_review_len) + +db_train = tf.data.Dataset.from_tensor_slices((x_train, y_train)) +db_train = db_train.shuffle(1000).batch(batchsz, drop_remainder=True) +db_test = tf.data.Dataset.from_tensor_slices((x_test, y_test)) +db_test = db_test.batch(batchsz, drop_remainder=True) +print('x_train shape:', x_train.shape, tf.reduce_max(y_train), tf.reduce_min(y_train)) +print('x_test shape:', x_test.shape) + + + +class MyRNN(keras.Model): + + def __init__(self, units): + super(MyRNN, self).__init__() + + # [b, 64] + self.state0 = [tf.zeros([batchsz, units])] + self.state1 = [tf.zeros([batchsz, units])] + + # transform text to embedding representation + # [b, 80] => [b, 80, 100] + self.embedding = layers.Embedding(total_words, embedding_len, + input_length=max_review_len) + + # [b, 80, 100] , h_dim: 64 + # RNN: cell1 ,cell2, cell3 + # SimpleRNN + # self.rnn_cell0 = layers.SimpleRNNCell(units, dropout=0.5) + # self.rnn_cell1 = layers.SimpleRNNCell(units, dropout=0.5) + self.rnn_cell0 = layers.GRUCell(units, dropout=0.5) + self.rnn_cell1 = layers.GRUCell(units, dropout=0.5) + + + # fc, [b, 80, 100] => [b, 64] => [b, 1] + self.outlayer = layers.Dense(1) + + def call(self, inputs, training=None): + """ + net(x) net(x, training=True) :train mode + net(x, training=False): test + :param inputs: [b, 80] + :param training: + :return: + """ + # [b, 80] + x = inputs + # embedding: [b, 80] => [b, 80, 100] + x = self.embedding(x) + # rnn cell compute + # [b, 80, 100] => [b, 64] + state0 = self.state0 + state1 = self.state1 + for word in tf.unstack(x, axis=1): # word: [b, 100] + # h1 = x*wxh+h0*whh + # out0: [b, 64] + out0, state0 = self.rnn_cell0(word, state0, training) + # out1: [b, 64] + out1, state1 = self.rnn_cell1(out0, state1, training) + + # out: [b, 64] => [b, 1] + x = self.outlayer(out1) + # p(y is pos|x) + prob = tf.sigmoid(x) + + return prob + +def main(): + units = 64 + epochs = 4 + + import time + + t0 = time.time() + + model = MyRNN(units) + model.compile(optimizer = keras.optimizers.Adam(0.001), + loss = tf.losses.BinaryCrossentropy(), + metrics=['accuracy'], experimental_run_tf_function=False) + model.fit(db_train, epochs=epochs, validation_data=db_test) + + model.evaluate(db_test) + + t1 = time.time() + # LSTM: 64.3 seconds, 83.4% + # GRU: 96.7s, 83.4% + print('total time cost:', t1-t0) + + +if __name__ == '__main__': + main() diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/gru_sentiment_analysis_layer.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/gru_sentiment_analysis_layer.py" new file mode 100644 index 0000000..7c28949 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/gru_sentiment_analysis_layer.py" @@ -0,0 +1,116 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + +import tensorflow as tf +import numpy as np +from tensorflow import keras +from tensorflow.keras import layers + + +tf.random.set_seed(22) +np.random.seed(22) +assert tf.__version__.startswith('2.') + +batchsz = 128 + +# the most frequest words +total_words = 10000 +max_review_len = 80 +embedding_len = 100 +(x_train, y_train), (x_test, y_test) = keras.datasets.imdb.load_data(num_words=total_words) +# x_train:[b, 80] +# x_test: [b, 80] +x_train = keras.preprocessing.sequence.pad_sequences(x_train, maxlen=max_review_len) +x_test = keras.preprocessing.sequence.pad_sequences(x_test, maxlen=max_review_len) + +db_train = tf.data.Dataset.from_tensor_slices((x_train, y_train)) +db_train = db_train.shuffle(1000).batch(batchsz, drop_remainder=True) +db_test = tf.data.Dataset.from_tensor_slices((x_test, y_test)) +db_test = db_test.batch(batchsz, drop_remainder=True) +print('x_train shape:', x_train.shape, tf.reduce_max(y_train), tf.reduce_min(y_train)) +print('x_test shape:', x_test.shape) + + + +class MyRNN(keras.Model): + + def __init__(self, units): + super(MyRNN, self).__init__() + + + # transform text to embedding representation + # [b, 80] => [b, 80, 100] + self.embedding = layers.Embedding(total_words, embedding_len, + input_length=max_review_len) + + # [b, 80, 100] , h_dim: 64 + self.rnn = keras.Sequential([ + # layers.SimpleRNN(units, dropout=0.5, return_sequences=True, unroll=True), + # layers.SimpleRNN(units, dropout=0.5, unroll=True) + + # unroll: Boolean (default False). If True, the network will be unrolled, + # else a symbolic loop will be used. + # Unrolling can speed-up a RNN, although it tends to be more memory-intensive. + # Unrolling is only suitable for short sequences. + layers.GRU(units, dropout=0.5, return_sequences=True, unroll=True), + layers.GRU(units, dropout=0.5, unroll=True) + ]) + + + # fc, [b, 80, 100] => [b, 64] => [b, 1] + self.outlayer = layers.Dense(1) + + def call(self, inputs, training=None): + """ + net(x) net(x, training=True) :train mode + net(x, training=False): test + :param inputs: [b, 80] + :param training: + :return: + """ + # [b, 80] + x = inputs + # embedding: [b, 80] => [b, 80, 100] + x = self.embedding(x) + # rnn cell compute + # x: [b, 80, 100] => [b, 64] + x = self.rnn(x,training=training) + + # out: [b, 64] => [b, 1] + x = self.outlayer(x) + # p(y is pos|x) + prob = tf.sigmoid(x) + + return prob + +def main(): + units = 64 + epochs = 4 + + import time + + + t0 = time.time() + model = MyRNN(units) + model.compile(optimizer = keras.optimizers.Adam(0.001), + loss = tf.losses.BinaryCrossentropy(), + metrics=['accuracy']) + + model.fit(db_train, epochs=epochs, validation_data=db_test) + + model.evaluate(db_test) + + + t1 = time.time() + # Unroll=True + # LSTM: 69.3 secnods, 83% + # GRU: 100 seconds, 83.4% + + # Unroll=False + # LSTM:23.71, 81.24 + # GRU 23.05, 83.11 + print('total time cost:', t1-t0) + + +if __name__ == '__main__': + main() diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/lstm_sentiment_analysis_cell.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/lstm_sentiment_analysis_cell.py" new file mode 100644 index 0000000..50d48da --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/lstm_sentiment_analysis_cell.py" @@ -0,0 +1,113 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + +import tensorflow as tf +import numpy as np +from tensorflow import keras +from tensorflow.keras import layers + + +tf.random.set_seed(22) +np.random.seed(22) +assert tf.__version__.startswith('2.') + +batchsz = 128 + +# the most frequest words +total_words = 10000 +max_review_len = 80 +embedding_len = 100 +(x_train, y_train), (x_test, y_test) = keras.datasets.imdb.load_data(num_words=total_words) +# x_train:[b, 80] +# x_test: [b, 80] +x_train = keras.preprocessing.sequence.pad_sequences(x_train, maxlen=max_review_len) +x_test = keras.preprocessing.sequence.pad_sequences(x_test, maxlen=max_review_len) + +db_train = tf.data.Dataset.from_tensor_slices((x_train, y_train)) +db_train = db_train.shuffle(1000).batch(batchsz, drop_remainder=True) +db_test = tf.data.Dataset.from_tensor_slices((x_test, y_test)) +db_test = db_test.batch(batchsz, drop_remainder=True) +print('x_train shape:', x_train.shape, tf.reduce_max(y_train), tf.reduce_min(y_train)) +print('x_test shape:', x_test.shape) + + + +class MyRNN(keras.Model): + + def __init__(self, units): + super(MyRNN, self).__init__() + + # [b, 64] + self.state0 = [tf.zeros([batchsz, units]),tf.zeros([batchsz, units])] + self.state1 = [tf.zeros([batchsz, units]),tf.zeros([batchsz, units])] + + # transform text to embedding representation + # [b, 80] => [b, 80, 100] + self.embedding = layers.Embedding(total_words, embedding_len, + input_length=max_review_len) + + # [b, 80, 100] , h_dim: 64 + # RNN: cell1 ,cell2, cell3 + # SimpleRNN + # self.rnn_cell0 = layers.SimpleRNNCell(units, dropout=0.5) + # self.rnn_cell1 = layers.SimpleRNNCell(units, dropout=0.5) + self.rnn_cell0 = layers.LSTMCell(units, dropout=0.5) + self.rnn_cell1 = layers.LSTMCell(units, dropout=0.5) + + + # fc, [b, 80, 100] => [b, 64] => [b, 1] + self.outlayer = layers.Dense(1) + + def call(self, inputs, training=None): + """ + net(x) net(x, training=True) :train mode + net(x, training=False): test + :param inputs: [b, 80] + :param training: + :return: + """ + # [b, 80] + x = inputs + # embedding: [b, 80] => [b, 80, 100] + x = self.embedding(x) + # rnn cell compute + # [b, 80, 100] => [b, 64] + state0 = self.state0 + state1 = self.state1 + for word in tf.unstack(x, axis=1): # word: [b, 100] + # h1 = x*wxh+h0*whh + # out0: [b, 64] + out0, state0 = self.rnn_cell0(word, state0, training) + # out1: [b, 64] + out1, state1 = self.rnn_cell1(out0, state1, training) + + # out: [b, 64] => [b, 1] + x = self.outlayer(out1) + # p(y is pos|x) + prob = tf.sigmoid(x) + + return prob + +def main(): + units = 64 + epochs = 4 + + import time + + t0 = time.time() + + model = MyRNN(units) + model.compile(optimizer = keras.optimizers.Adam(0.001), + loss = tf.losses.BinaryCrossentropy(), + metrics=['accuracy'],experimental_run_tf_function=False) + model.fit(db_train, epochs=epochs, validation_data=db_test) + + model.evaluate(db_test) + + t1 = time.time() + # 64.3 seconds, 83.4% + print('total time cost:', t1-t0) + + +if __name__ == '__main__': + main() diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/lstm_sentiment_analysis_layer.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/lstm_sentiment_analysis_layer.py" new file mode 100644 index 0000000..8b2e47e --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson47-LSTM\345\256\236\346\210\230/lstm_sentiment_analysis_layer.py" @@ -0,0 +1,105 @@ +import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + +import tensorflow as tf +import numpy as np +from tensorflow import keras +from tensorflow.keras import layers + + +tf.random.set_seed(22) +np.random.seed(22) +assert tf.__version__.startswith('2.') + +batchsz = 128 + +# the most frequest words +total_words = 10000 +max_review_len = 80 +embedding_len = 100 +(x_train, y_train), (x_test, y_test) = keras.datasets.imdb.load_data(num_words=total_words) +# x_train:[b, 80] +# x_test: [b, 80] +x_train = keras.preprocessing.sequence.pad_sequences(x_train, maxlen=max_review_len) +x_test = keras.preprocessing.sequence.pad_sequences(x_test, maxlen=max_review_len) + +db_train = tf.data.Dataset.from_tensor_slices((x_train, y_train)) +db_train = db_train.shuffle(1000).batch(batchsz, drop_remainder=True) +db_test = tf.data.Dataset.from_tensor_slices((x_test, y_test)) +db_test = db_test.batch(batchsz, drop_remainder=True) +print('x_train shape:', x_train.shape, tf.reduce_max(y_train), tf.reduce_min(y_train)) +print('x_test shape:', x_test.shape) + + + +class MyRNN(keras.Model): + + def __init__(self, units): + super(MyRNN, self).__init__() + + + # transform text to embedding representation + # [b, 80] => [b, 80, 100] + self.embedding = layers.Embedding(total_words, embedding_len, + input_length=max_review_len) + + # [b, 80, 100] , h_dim: 64 + self.rnn = keras.Sequential([ + # layers.SimpleRNN(units, dropout=0.5, return_sequences=True, unroll=True), + # layers.SimpleRNN(units, dropout=0.5, unroll=True) + + layers.LSTM(units, dropout=0.5, return_sequences=True, unroll=True), + layers.LSTM(units, dropout=0.5, unroll=True) + ]) + + + # fc, [b, 80, 100] => [b, 64] => [b, 1] + self.outlayer = layers.Dense(1) + + def call(self, inputs, training=None): + """ + net(x) net(x, training=True) :train mode + net(x, training=False): test + :param inputs: [b, 80] + :param training: + :return: + """ + # [b, 80] + x = inputs + # embedding: [b, 80] => [b, 80, 100] + x = self.embedding(x) + # rnn cell compute + # x: [b, 80, 100] => [b, 64] + x = self.rnn(x,training=training) + + # out: [b, 64] => [b, 1] + x = self.outlayer(x) + # p(y is pos|x) + prob = tf.sigmoid(x) + + return prob + +def main(): + units = 64 + epochs = 4 + + import time + + t0 = time.time() + + model = MyRNN(units) + model.compile(optimizer = keras.optimizers.Adam(0.001), + loss = tf.losses.BinaryCrossentropy(), + metrics=['accuracy']) + model.fit(db_train, epochs=epochs, validation_data=db_test) + + model.evaluate(db_test) + + + t1 = time.time() + # 69.3 secnods, 83% + print('total time cost:', t1-t0) + + +if __name__ == '__main__': + main() diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson49-VAE\345\256\236\346\210\230/autoencoder.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson49-VAE\345\256\236\346\210\230/autoencoder.py" index d3f19c4..f3c4890 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson49-VAE\345\256\236\346\210\230/autoencoder.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson49-VAE\345\256\236\346\210\230/autoencoder.py" @@ -1,4 +1,6 @@ import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf import numpy as np from tensorflow import keras @@ -9,8 +11,7 @@ tf.random.set_seed(22) -np.random.seed(22) -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +np.random.seed(22) assert tf.__version__.startswith('2.') diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson49-VAE\345\256\236\346\210\230/vae.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson49-VAE\345\256\236\346\210\230/vae.py" index 583ed33..cc70d2d 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson49-VAE\345\256\236\346\210\230/vae.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson49-VAE\345\256\236\346\210\230/vae.py" @@ -1,4 +1,6 @@ import os +os.environ['TF_CPP_MIN_LOG_LEVEL']='2' + import tensorflow as tf import numpy as np from tensorflow import keras @@ -9,8 +11,7 @@ tf.random.set_seed(22) -np.random.seed(22) -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +np.random.seed(22) assert tf.__version__.startswith('2.') @@ -81,7 +82,7 @@ def reparameterize(self, mu, log_var): eps = tf.random.normal(log_var.shape) - std = tf.exp(log_var*0.5) + std = tf.exp(log_var)**0.5 z = mu + std * eps return z diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson51-WGAN\345\256\236\346\210\230/gan_train.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson51-WGAN\345\256\236\346\210\230/gan_train.py" index 92a8104..21434cf 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson51-WGAN\345\256\236\346\210\230/gan_train.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson51-WGAN\345\256\236\346\210\230/gan_train.py" @@ -1,8 +1,9 @@ import os +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import numpy as np import tensorflow as tf -from tensorflow import keras -from scipy.misc import toimage +from tensorflow import keras +from PIL import Image import glob from gan import Generator, Discriminator @@ -36,8 +37,8 @@ def preprocess(img): single_row = np.array([]) if final_image.shape[2] == 1: - final_image = np.squeeze(final_image, axis=2) - toimage(final_image).save(image_path) + final_image = np.squeeze(final_image, axis=2) + Image.fromarray(final_image).save(image_path) def celoss_ones(logits): @@ -82,7 +83,6 @@ def main(): tf.random.set_seed(22) np.random.seed(22) - os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' assert tf.__version__.startswith('2.') @@ -94,7 +94,8 @@ def main(): is_training = True - img_path = glob.glob(r'C:\Users\Jackie Loong\Downloads\DCGAN-LSGAN-WGAN-GP-DRAGAN-Tensorflow-2-master\data\faces\*.jpg') + img_path = glob.glob(r'C:\Users\Jackie\Downloads\faces\*.jpg') + assert len(img_path) > 0 dataset, img_shape, _ = make_anime_dataset(img_path, batch_size) print(dataset, img_shape) @@ -110,15 +111,14 @@ def main(): discriminator = Discriminator() discriminator.build(input_shape=(None, 64, 64, 3)) - g_optimizer = tf.optimizers.Adam(learning_rate=learning_rate, beta_1=0.5) - d_optimizer = tf.optimizers.Adam(learning_rate=learning_rate, beta_1=0.5) + g_optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate, beta_1=0.5) + d_optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate, beta_1=0.5) for epoch in range(epochs): - batch_z = tf.random.uniform([batch_size, z_dim], minval=-1., maxval=1.) + batch_z = tf.random.normal([batch_size, z_dim]) batch_x = next(db_iter) - # train D with tf.GradientTape() as tape: d_loss = d_loss_fn(generator, discriminator, batch_z, batch_x, is_training) @@ -126,6 +126,7 @@ def main(): d_optimizer.apply_gradients(zip(grads, discriminator.trainable_variables)) + batch_z = tf.random.normal([batch_size, z_dim]) with tf.GradientTape() as tape: g_loss = g_loss_fn(generator, discriminator, batch_z, is_training) grads = tape.gradient(g_loss, generator.trainable_variables) @@ -134,7 +135,7 @@ def main(): if epoch % 100 == 0: print(epoch, 'd-loss:',float(d_loss), 'g-loss:', float(g_loss)) - z = tf.random.uniform([100, z_dim]) + z = tf.random.normal([100, z_dim]) fake_image = generator(z, training=False) img_path = os.path.join('images', 'gan-%d.png'%epoch) save_result(fake_image.numpy(), 10, img_path, color_mode='P') diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson51-WGAN\345\256\236\346\210\230/wgan_train.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson51-WGAN\345\256\236\346\210\230/wgan_train.py" index f687f12..e814160 100644 --- "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson51-WGAN\345\256\236\346\210\230/wgan_train.py" +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson51-WGAN\345\256\236\346\210\230/wgan_train.py" @@ -1,8 +1,10 @@ import os +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' import numpy as np import tensorflow as tf from tensorflow import keras -from scipy.misc import toimage + +from PIL import Image import glob from gan import Generator, Discriminator @@ -36,24 +38,24 @@ def preprocess(img): single_row = np.array([]) if final_image.shape[2] == 1: - final_image = np.squeeze(final_image, axis=2) - toimage(final_image).save(image_path) + final_image = np.squeeze(final_image, axis=2) + Image.fromarray(final_image).save(image_path) def celoss_ones(logits): # [b, 1] # [b] = [1, 1, 1, 1,] - loss = tf.nn.sigmoid_cross_entropy_with_logits(logits=logits, - labels=tf.ones_like(logits)) - return tf.reduce_mean(loss) + # loss = tf.keras.losses.categorical_crossentropy(y_pred=logits, + # y_true=tf.ones_like(logits)) + return - tf.reduce_mean(logits) def celoss_zeros(logits): # [b, 1] # [b] = [1, 1, 1, 1,] - loss = tf.nn.sigmoid_cross_entropy_with_logits(logits=logits, - labels=tf.zeros_like(logits)) - return tf.reduce_mean(loss) + # loss = tf.keras.losses.categorical_crossentropy(y_pred=logits, + # y_true=tf.zeros_like(logits)) + return tf.reduce_mean(logits) def gradient_penalty(discriminator, batch_x, fake_image): @@ -69,7 +71,7 @@ def gradient_penalty(discriminator, batch_x, fake_image): with tf.GradientTape() as tape: tape.watch([interplate]) - d_interplote_logits = discriminator(interplate) + d_interplote_logits = discriminator(interplate, training=True) grads = tape.gradient(d_interplote_logits, interplate) # grads:[b, h, w, c] => [b, -1] @@ -92,7 +94,7 @@ def d_loss_fn(generator, discriminator, batch_z, batch_x, is_training): d_loss_fake = celoss_zeros(d_fake_logits) gp = gradient_penalty(discriminator, batch_x, fake_image) - loss = d_loss_fake + d_loss_real + 1. * gp + loss = d_loss_real + d_loss_fake + 10. * gp return loss, gp @@ -105,11 +107,11 @@ def g_loss_fn(generator, discriminator, batch_z, is_training): return loss + def main(): - tf.random.set_seed(22) - np.random.seed(22) - os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' + tf.random.set_seed(233) + np.random.seed(233) assert tf.__version__.startswith('2.') @@ -117,11 +119,13 @@ def main(): z_dim = 100 epochs = 3000000 batch_size = 512 - learning_rate = 0.002 + learning_rate = 0.0005 is_training = True - img_path = glob.glob(r'C:\Users\Jackie Loong\Downloads\DCGAN-LSGAN-WGAN-GP-DRAGAN-Tensorflow-2-master\data\faces\*.jpg') + img_path = glob.glob(r'C:\Users\Jackie\Downloads\faces\*.jpg') + assert len(img_path) > 0 + dataset, img_shape, _ = make_anime_dataset(img_path, batch_size) print(dataset, img_shape) @@ -132,26 +136,30 @@ def main(): db_iter = iter(dataset) - generator = Generator() + generator = Generator() generator.build(input_shape = (None, z_dim)) discriminator = Discriminator() discriminator.build(input_shape=(None, 64, 64, 3)) + z_sample = tf.random.normal([100, z_dim]) - g_optimizer = tf.optimizers.Adam(learning_rate=learning_rate, beta_1=0.5) - d_optimizer = tf.optimizers.Adam(learning_rate=learning_rate, beta_1=0.5) + g_optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate, beta_1=0.5) + d_optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate, beta_1=0.5) - for epoch in range(epochs): - batch_z = tf.random.uniform([batch_size, z_dim], minval=-1., maxval=1.) - batch_x = next(db_iter) + for epoch in range(epochs): - # train D - with tf.GradientTape() as tape: - d_loss, gp = d_loss_fn(generator, discriminator, batch_z, batch_x, is_training) - grads = tape.gradient(d_loss, discriminator.trainable_variables) - d_optimizer.apply_gradients(zip(grads, discriminator.trainable_variables)) + for _ in range(5): + batch_z = tf.random.normal([batch_size, z_dim]) + batch_x = next(db_iter) + # train D + with tf.GradientTape() as tape: + d_loss, gp = d_loss_fn(generator, discriminator, batch_z, batch_x, is_training) + grads = tape.gradient(d_loss, discriminator.trainable_variables) + d_optimizer.apply_gradients(zip(grads, discriminator.trainable_variables)) + + batch_z = tf.random.normal([batch_size, z_dim]) with tf.GradientTape() as tape: g_loss = g_loss_fn(generator, discriminator, batch_z, is_training) @@ -162,7 +170,7 @@ def main(): print(epoch, 'd-loss:',float(d_loss), 'g-loss:', float(g_loss), 'gp:', float(gp)) - z = tf.random.uniform([100, z_dim]) + z = tf.random.normal([100, z_dim]) fake_image = generator(z, training=False) img_path = os.path.join('images', 'wgan-%d.png'%epoch) save_result(fake_image.numpy(), 10, img_path, color_mode='P') diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/pokemon.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/pokemon.py" new file mode 100644 index 0000000..bef5104 --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/pokemon.py" @@ -0,0 +1,140 @@ +import os, glob +import random, csv + +import tensorflow as tf + + + +def load_csv(root, filename, name2label): + # root:æ•°æ�®é›†æ ¹ç›®å½• + # filename:csv文件å�� + # name2label:类别å��ç¼–ç �表 + if not os.path.exists(os.path.join(root, filename)): + images = [] + for name in name2label.keys(): + # 'pokemon\\mewtwo\\00001.png + images += glob.glob(os.path.join(root, name, '*.png')) + images += glob.glob(os.path.join(root, name, '*.jpg')) + images += glob.glob(os.path.join(root, name, '*.jpeg')) + + # 1167, 'pokemon\\bulbasaur\\00000000.png' + print(len(images), images) + + random.shuffle(images) + with open(os.path.join(root, filename), mode='w', newline='') as f: + writer = csv.writer(f) + for img in images: # 'pokemon\\bulbasaur\\00000000.png' + name = img.split(os.sep)[-2] + label = name2label[name] + # 'pokemon\\bulbasaur\\00000000.png', 0 + writer.writerow([img, label]) + print('written into csv file:', filename) + + # read from csv file + images, labels = [], [] + with open(os.path.join(root, filename)) as f: + reader = csv.reader(f) + for row in reader: + # 'pokemon\\bulbasaur\\00000000.png', 0 + img, label = row + label = int(label) + + images.append(img) + labels.append(label) + + assert len(images) == len(labels) + + return images, labels + + +def load_pokemon(root, mode='train'): + # 创建数å—ç¼–ç �表 + name2label = {} # "sq...":0 + for name in sorted(os.listdir(os.path.join(root))): + if not os.path.isdir(os.path.join(root, name)): + continue + # ç»™æ¯�个类别编ç �ä¸€ä¸ªæ•°å— + name2label[name] = len(name2label.keys()) + + # 读å�–Labelä¿¡æ�¯ + # [file1,file2,], [3,1] + images, labels = load_csv(root, 'images.csv', name2label) + + if mode == 'train': # 60% + images = images[:int(0.6 * len(images))] + labels = labels[:int(0.6 * len(labels))] + elif mode == 'val': # 20% = 60%->80% + images = images[int(0.6 * len(images)):int(0.8 * len(images))] + labels = labels[int(0.6 * len(labels)):int(0.8 * len(labels))] + else: # 20% = 80%->100% + images = images[int(0.8 * len(images)):] + labels = labels[int(0.8 * len(labels)):] + + return images, labels, name2label + + +img_mean = tf.constant([0.485, 0.456, 0.406]) +img_std = tf.constant([0.229, 0.224, 0.225]) +def normalize(x, mean=img_mean, std=img_std): + # x: [224, 224, 3] + # mean: [224, 224, 3], std: [3] + x = (x - mean)/std + return x + +def denormalize(x, mean=img_mean, std=img_std): + x = x * std + mean + return x + +def preprocess(x,y): + # x: 图片的路径,y:图片的数å—ç¼–ç � + x = tf.io.read_file(x) + x = tf.image.decode_jpeg(x, channels=3) # RGBA + x = tf.image.resize(x, [244, 244]) + + # data augmentation, 0~255 + # x = tf.image.random_flip_up_down(x) + x= tf.image.random_flip_left_right(x) + x = tf.image.random_crop(x, [224, 224, 3]) + + # x: [0,255]=> 0~1 + x = tf.cast(x, dtype=tf.float32) / 255. + # 0~1 => D(0,1) + x = normalize(x) + + y = tf.convert_to_tensor(y) + + return x, y + + +def main(): + import time + + + + + images, labels, table = load_pokemon('pokemon', 'train') + print('images', len(images), images) + print('labels', len(labels), labels) + print(table) + + # images: string path + # labels: number + db = tf.data.Dataset.from_tensor_slices((images, labels)) + db = db.shuffle(1000).map(preprocess).batch(32) + + writter = tf.summary.create_file_writer('logs') + + for step, (x,y) in enumerate(db): + + # x: [32, 224, 224, 3] + # y: [32] + with writter.as_default(): + x = denormalize(x) + tf.summary.image('img',x,step=step,max_outputs=9) + time.sleep(5) + + + + +if __name__ == '__main__': + main() \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/resnet.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/resnet.py" new file mode 100644 index 0000000..63eaf5f --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/resnet.py" @@ -0,0 +1,119 @@ +import os +import tensorflow as tf +import numpy as np +from tensorflow import keras +from tensorflow.keras import layers + + + +tf.random.set_seed(22) +np.random.seed(22) +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +assert tf.__version__.startswith('2.') + + + +class ResnetBlock(keras.Model): + + def __init__(self, channels, strides=1): + super(ResnetBlock, self).__init__() + + self.channels = channels + self.strides = strides + + self.conv1 = layers.Conv2D(channels, 3, strides=strides, + padding=[[0,0],[1,1],[1,1],[0,0]]) + self.bn1 = keras.layers.BatchNormalization() + self.conv2 = layers.Conv2D(channels, 3, strides=1, + padding=[[0,0],[1,1],[1,1],[0,0]]) + self.bn2 = keras.layers.BatchNormalization() + + if strides!=1: + self.down_conv = layers.Conv2D(channels, 1, strides=strides, padding='valid') + self.down_bn = tf.keras.layers.BatchNormalization() + + def call(self, inputs, training=None): + residual = inputs + + x = self.conv1(inputs) + x = tf.nn.relu(x) + x = self.bn1(x, training=training) + x = self.conv2(x) + x = tf.nn.relu(x) + x = self.bn2(x, training=training) + + # 残差连接 + if self.strides!=1: + residual = self.down_conv(inputs) + residual = tf.nn.relu(residual) + residual = self.down_bn(residual, training=training) + + x = x + residual + x = tf.nn.relu(x) + return x + + +class ResNet(keras.Model): + + def __init__(self, num_classes, initial_filters=16, **kwargs): + super(ResNet, self).__init__(**kwargs) + + self.stem = layers.Conv2D(initial_filters, 3, strides=3, padding='valid') + + self.blocks = keras.models.Sequential([ + ResnetBlock(initial_filters * 2, strides=3), + ResnetBlock(initial_filters * 2, strides=1), + # layers.Dropout(rate=0.5), + + ResnetBlock(initial_filters * 4, strides=3), + ResnetBlock(initial_filters * 4, strides=1), + + ResnetBlock(initial_filters * 8, strides=2), + ResnetBlock(initial_filters * 8, strides=1), + + ResnetBlock(initial_filters * 16, strides=2), + ResnetBlock(initial_filters * 16, strides=1), + ]) + + self.final_bn = layers.BatchNormalization() + self.avg_pool = layers.GlobalMaxPool2D() + self.fc = layers.Dense(num_classes) + + def call(self, inputs, training=None): + # print('x:',inputs.shape) + out = self.stem(inputs,training=training) + out = tf.nn.relu(out) + + # print('stem:',out.shape) + + out = self.blocks(out, training=training) + # print('res:',out.shape) + + out = self.final_bn(out, training=training) + # out = tf.nn.relu(out) + + out = self.avg_pool(out) + + # print('avg_pool:',out.shape) + out = self.fc(out) + + # print('out:',out.shape) + + return out + + + +def main(): + num_classes = 5 + + resnet18 = ResNet(5) + resnet18.build(input_shape=(4,224,224,3)) + resnet18.summary() + + + + + + +if __name__ == '__main__': + main() diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/train_scratch.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/train_scratch.py" new file mode 100644 index 0000000..19ab5da --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/train_scratch.py" @@ -0,0 +1,105 @@ +import os + +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' + + +import tensorflow as tf +import numpy as np +from tensorflow import keras +from tensorflow.keras import layers,optimizers,losses +from tensorflow.keras.callbacks import EarlyStopping + +tf.random.set_seed(22) +np.random.seed(22) +assert tf.__version__.startswith('2.') +# 设置GPUæ˜¾å˜æŒ‰éœ€åˆ†é…� +gpus = tf.config.experimental.list_physical_devices('GPU') +if gpus: + try: + # Currently, memory growth needs to be the same across GPUs + for gpu in gpus: + tf.config.experimental.set_memory_growth(gpu, True) + logical_gpus = tf.config.experimental.list_logical_devices('GPU') + print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs") + except RuntimeError as e: + # Memory growth must be set before GPUs have been initialized + print(e) + + +from pokemon import load_pokemon, normalize, denormalize +from resnet import ResNet + + +def preprocess(x,y): + # x: 图片的路径,y:图片的数å—ç¼–ç � + x = tf.io.read_file(x) + x = tf.image.decode_jpeg(x, channels=3) # RGBA + # 图片缩放 + # x = tf.image.resize(x, [244, 244]) + # 图片旋转 + # x = tf.image.rot90(x,2) + # éš�机水平翻转 + x = tf.image.random_flip_left_right(x) + # éš�机竖直翻转 + # x = tf.image.random_flip_up_down(x) + + # 图片先缩放到ç¨�大尺寸 + x = tf.image.resize(x, [244, 244]) + # å†�éš�机è£�剪到å�ˆé€‚尺寸 + x = tf.image.random_crop(x, [224,224,3]) + + # x: [0,255]=> -1~1 + x = tf.cast(x, dtype=tf.float32) / 255. + x = normalize(x) + y = tf.convert_to_tensor(y) + y = tf.one_hot(y, depth=5) + + return x, y + + +batchsz = 256 + +# creat train db +images, labels, table = load_pokemon('pokemon',mode='train') +db_train = tf.data.Dataset.from_tensor_slices((images, labels)) +db_train = db_train.shuffle(1000).map(preprocess).batch(batchsz) +# crate validation db +images2, labels2, table = load_pokemon('pokemon',mode='val') +db_val = tf.data.Dataset.from_tensor_slices((images2, labels2)) +db_val = db_val.map(preprocess).batch(batchsz) +# create test db +images3, labels3, table = load_pokemon('pokemon',mode='test') +db_test = tf.data.Dataset.from_tensor_slices((images3, labels3)) +db_test = db_test.map(preprocess).batch(batchsz) + + +resnet = keras.Sequential([ + layers.Conv2D(16,5,3), + layers.MaxPool2D(3,3), + layers.ReLU(), + layers.Conv2D(64,5,3), + layers.MaxPool2D(2,2), + layers.ReLU(), + layers.Flatten(), + layers.Dense(64), + layers.ReLU(), + layers.Dense(5) +]) + + +resnet = ResNet(5) +resnet.build(input_shape=(4, 224, 224, 3)) +resnet.summary() + +early_stopping = EarlyStopping( + monitor='val_accuracy', + min_delta=0.001, + patience=5 +) + +resnet.compile(optimizer=optimizers.Adam(lr=1e-3), + loss=losses.CategoricalCrossentropy(from_logits=True), + metrics=['accuracy']) +resnet.fit(db_train, validation_data=db_val, validation_freq=1, epochs=100, + callbacks=[early_stopping]) +resnet.evaluate(db_test) \ No newline at end of file diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/train_transfer.py" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/train_transfer.py" new file mode 100644 index 0000000..208edfa --- /dev/null +++ "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/train_transfer.py" @@ -0,0 +1,82 @@ +import os +import tensorflow as tf +import numpy as np +from tensorflow import keras +from tensorflow.keras import layers + + + +import os +import tensorflow as tf +import numpy as np +from tensorflow import keras +from tensorflow.keras import layers,optimizers,losses +from tensorflow.keras.callbacks import EarlyStopping + +tf.random.set_seed(22) +np.random.seed(22) +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' +assert tf.__version__.startswith('2.') + + +from pokemon import load_pokemon,normalize + + + +def preprocess(x,y): + # x: 图片的路径,y:图片的数å—ç¼–ç � + x = tf.io.read_file(x) + x = tf.image.decode_jpeg(x, channels=3) # RGBA + x = tf.image.resize(x, [244, 244]) + + # x = tf.image.random_flip_left_right(x) + x = tf.image.random_flip_up_down(x) + x = tf.image.random_crop(x, [224,224,3]) + + # x: [0,255]=> -1~1 + x = tf.cast(x, dtype=tf.float32) / 255. + x = normalize(x) + y = tf.convert_to_tensor(y) + y = tf.one_hot(y, depth=5) + + return x, y + + +batchsz = 128 +# 创建è®ç»ƒé›†Datset对象 +images, labels, table = load_pokemon('pokemon',mode='train') +db_train = tf.data.Dataset.from_tensor_slices((images, labels)) +db_train = db_train.shuffle(1000).map(preprocess).batch(batchsz) +# 创建验è¯�集Datset对象 +images2, labels2, table = load_pokemon('pokemon',mode='val') +db_val = tf.data.Dataset.from_tensor_slices((images2, labels2)) +db_val = db_val.map(preprocess).batch(batchsz) +# 创建测试集Datset对象 +images3, labels3, table = load_pokemon('pokemon',mode='test') +db_test = tf.data.Dataset.from_tensor_slices((images3, labels3)) +db_test = db_test.map(preprocess).batch(batchsz) + +# +net = keras.applications.VGG19(weights='imagenet', include_top=False, + pooling='max') +net.trainable = False +newnet = keras.Sequential([ + net, + layers.Dense(5) +]) +newnet.build(input_shape=(4,224,224,3)) +newnet.summary() + + +early_stopping = EarlyStopping( + monitor='val_accuracy', + min_delta=0.001, + patience=5 +) + +newnet.compile(optimizer=optimizers.Adam(lr=1e-3), + loss=losses.CategoricalCrossentropy(from_logits=True), + metrics=['accuracy']) +newnet.fit(db_train, validation_data=db_val, validation_freq=1, epochs=100, + callbacks=[early_stopping]) +newnet.evaluate(db_test) diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/\345\256\235\345\217\257\346\242\246\346\225\260\346\215\256\351\233\206.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/\345\256\235\345\217\257\346\242\246\346\225\260\346\215\256\351\233\206.pdf" new file mode 100644 index 0000000..2139b46 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson52-\350\207\252\345\256\232\344\271\211\346\225\260\346\215\256\351\233\206\345\222\214\350\277\201\347\247\273\345\255\246\344\271\240/\345\256\235\345\217\257\346\242\246\346\225\260\346\215\256\351\233\206.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson53-YOLO\347\233\256\346\240\207\346\243\200\346\265\213/YOLO.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson53-YOLO\347\233\256\346\240\207\346\243\200\346\265\213/YOLO.pdf" new file mode 100644 index 0000000..77dde8c Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson53-YOLO\347\233\256\346\240\207\346\243\200\346\265\213/YOLO.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson53-YOLO\347\233\256\346\240\207\346\243\200\346\265\213/YOLO\345\256\236\346\210\230.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson53-YOLO\347\233\256\346\240\207\346\243\200\346\265\213/YOLO\345\256\236\346\210\230.pdf" new file mode 100644 index 0000000..4e18550 Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson53-YOLO\347\233\256\346\240\207\346\243\200\346\265\213/YOLO\345\256\236\346\210\230.pdf" differ diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson53-YOLO\347\233\256\346\240\207\346\243\200\346\265\213/\344\273\243\347\240\201\351\234\200\350\264\255\344\271\260\350\257\276\347\250\213\345\271\266\345\212\240\347\276\244\344\270\213\350\275\275(\347\275\221\346\230\223\344\272\221\350\257\276\345\240\202).txt" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson53-YOLO\347\233\256\346\240\207\346\243\200\346\265\213/\344\273\243\347\240\201\351\234\200\350\264\255\344\271\260\350\257\276\347\250\213\345\271\266\345\212\240\347\276\244\344\270\213\350\275\275(\347\275\221\346\230\223\344\272\221\350\257\276\345\240\202).txt" new file mode 100644 index 0000000..e69de29 diff --git "a/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson\351\200\211\347\234\213-\344\272\272\345\267\245\346\231\272\350\203\275\345\217\221\345\261\225\345\217\262/\344\272\272\345\267\245\346\231\272\350\203\275\345\217\221\345\261\225\345\217\262.pdf" "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson\351\200\211\347\234\213-\344\272\272\345\267\245\346\231\272\350\203\275\345\217\221\345\261\225\345\217\262/\344\272\272\345\267\245\346\231\272\350\203\275\345\217\221\345\261\225\345\217\262.pdf" new file mode 100644 index 0000000..e84b75e Binary files /dev/null and "b/\346\267\261\345\272\246\345\255\246\344\271\240\344\270\216TensorFlow\345\205\245\351\227\250\345\256\236\346\210\230-\346\272\220\347\240\201\345\222\214PPT/lesson\351\200\211\347\234\213-\344\272\272\345\267\245\346\231\272\350\203\275\345\217\221\345\261\225\345\217\262/\344\272\272\345\267\245\346\231\272\350\203\275\345\217\221\345\261\225\345\217\262.pdf" differ