古月《ROS入门21讲》18.tf坐标系广播与监听的编程实现.pdf
18.tf坐标系广播与监听的编程实现 主 讲 人 : 古 月 创建功能包 创建tf广播器代码(C++) • • • turtle_tf_broadcaster.cpp 创建tf监听器代码(C++) • • turtle_tf_listener.cpp 配置tf广播器与监听器代码编译规则 • • CMakeLists.txt 编译并运行 创建tf广播器与监听器代码(Python) 创建tf广播器与监听器代码(Python) turtle_tf_broadcaster.py turtle_tf_listener.py 感谢观看 怕什么真理无穷,进一寸有一寸的欢喜 更多精彩,欢迎关注 ?0 码力 | 8 页 | 1.19 MB | 1 年前3【PyTorch深度学习-龙龙老师】-测试版202112
import tensorflow as tf # 导入 TensorFlow 库 # 1.创建计算图阶段,此处代码需要使用 tf 1.x 版本运行 # 创建 2 个输入端子,并指定类型和名字 a_ph = tf.placeholder(tf.float32, name='variable_a') b_ph = tf.placeholder(tf.float32, name='variable_b') 创建输出端子的运算操作,并命名 c_op = tf.add(a_ph, b_ph, name='variable_c') 创建计算图的过程就类比通过符号建立公式? = ? + ?的过程,仅仅是记录了公式的计算步 骤,并没有实际计算公式的数值结果,需要通过运行公式的输出端子?,并赋值? = 2.0,? = 4.0才能获得?的数值结果,代码如下: # 2.运行计算图阶段,此处代码需要使用 tf 1.x 版本运行 # # 创建运行环境 sess = tf.InteractiveSession() # 初始化步骤也需要作为操作运行 init = tf.global_variables_initializer() sess.run(init) # 运行初始化操作,完成初始化 # 运行输出端子,需要给输入端子赋值 c_numpy = sess.run(c_op, feed_dict={a_ph:0 码力 | 439 页 | 29.91 MB | 1 年前32 使用Python训练和部署低精度模型 张校捷
t定点数表示 使用低精度的意义 深度学习模型中实数的表示 FP32: E8M23 FP16: E8M7 FP16: E5M10 Int8 (TPU, tf.bfloat16) (tf.float32) (GPU, tf.float16) 低精度浮点数的优点 1.节约内存/显存的使用(FP16为原来的1/2,int8为原来的1/4) 2.特殊的硬件专门用于低精度浮点数的计算加速(TensorCore) 如果FP32要使用,可以设置(内部转为FP16): TF_ENABLE_CUBLAS_TENSOR_OP_MATH_FP32=1 TF_ENABLE_CUDNN_TENSOR_OP_MATH_FP32=1 TF_ENABLE_CUDNN_RNN_TENSOR_OP_MATH_FP32=1 TensorFlow手动转换模型 import tensorflow as tf import numpy as numpy numpy input = tf.placeholder(dtype=tf.float32, shape=[None, 128, 128, 16]) input_fp16 = tf.cast(input, dtype=tf.float16) # Force the layer use tf.float16 conv1 = tf.keras.layers.Conv2D(32, (3,3), 1, "same"0 码力 | 24 页 | 981.45 KB | 1 年前3《Efficient Deep Learning Book》[EDL] Chapter 4 - Efficient Architectures
short texts with padding tokens and truncating the longer ones to 250 tokens. import tensorflow as tf # Size of our vocabulary. vocab_size = 5000 # This controls the max number of tokens the layer with with tokenize, by truncating # the rest of the sequence. max_seq_len = 100 vectorization_layer = tf.keras.layers.TextVectorization( max_tokens=vocab_size, output_sequence_length=max_seq_len) Once we the vocabulary. # This step allows the vectorization layer to build the vocabulary. train_text_ds = tf.data.Dataset.from_tensor_slices(x_train).batch(512) vectorization_layer.adapt(train_text_ds) Let’s0 码力 | 53 页 | 3.92 MB | 1 年前3《Efficient Deep Learning Book》[EDL] Chapter 7 - Automation
tensorflow as tf import numpy as np from tensorflow.keras import layers, losses, optimizers X = tf.random.uniform((20, 5)) Y = tf.squeeze( tf.one_hot(tf.random.uniform((20, 1), 0, 5, tf.int64), 5) ) whose size is determined by the input size parameter. def create_model(size): return tf.keras.Sequential([ tf.keras.Input(shape=(5,5)), layers.Dense(size, activation='relu'), layers.Dense(5, activation='softmax') SGD(learning_rate=learning_rate) losses = [] for iteration in range(2000): with tf.GradientTape() as tape: output = model(X) loss = tf.reduce_mean(tf.math.square(Y - output)) grads = tape.gradient(loss, model.trainable_variables)0 码力 | 33 页 | 2.48 MB | 1 年前3《Efficient Deep Learning Book》[EDL] Chapter 3 - Learning Techniques
images. import tensorflow as tf # Target image size IMG_SIZE = 264 def dsitem_to_tuple(item): return (item['image'], item['label']) def resize_image(image, label): image = tf.image.resize(image, [IMG_SIZE [IMG_SIZE, IMG_SIZE]) image = tf.cast(image, tf.uint8) return image, label train_ds = train_ds.map(dsitem_to_tuple).map(resize_image).cache() val_ds = val_ds.map(dsitem_to_tuple).map(resize_image).cache() preprocessing, core and softmax layers. model = tf.keras.Sequential([ layers.Input([IMG_SIZE, IMG_SIZE, 3], dtype = tf.uint8), layers.Lambda(lambda x: tf.cast(x, tf.float32)), layers.Lambda(lambda x: apps0 码力 | 56 页 | 18.93 MB | 1 年前3Exactly-once fault-tolerance in Apache Flink - CS 591 K1: Data Stream Processing and Analytics Spring 2020
9TwJBEJ3zE/ELtbTZCZW5I5G7Yg2lph4QAIXsrcMsLJ3e9ndMyEX/oONh Rpbf5Cd/8YFrlDwJZO8vDeTmXlhIrg2rvtrK1vbG5tF3aKu3v7B4elo+Omlqli6DMpGqHVKPgMfqG 4HtRCGNQoGtcHw781tPqDSX8YOZJBhEdBjzAWfUWKlZwaTnVXqlslt15yCrxMtJGXI0eqWvbl+yNMLYME 9TwJBEJ3zE/ELtbTZCZW5I5G7Yg2lph4QAIXsrcMsLJ3e9ndMyEX/oONh Rpbf5Cd/8YFrlDwJZO8vDeTmXlhIrg2rvtrK1vbG5tF3aKu3v7B4elo+Omlqli6DMpGqHVKPgMfqG 4HtRCGNQoGtcHw781tPqDSX8YOZJBhEdBjzAWfUWKlZwaTnVXqlslt15yCrxMtJGXI0eqWvbl+yNMLYME 9TwJBEJ3zE/ELtbTZCZW5I5G7Yg2lph4QAIXsrcMsLJ3e9ndMyEX/oONh Rpbf5Cd/8YFrlDwJZO8vDeTmXlhIrg2rvtrK1vbG5tF3aKu3v7B4elo+Omlqli6DMpGqHVKPgMfqG 4HtRCGNQoGtcHw781tPqDSX8YOZJBhEdBjzAWfUWKlZwaTnVXqlslt15yCrxMtJGXI0eqWvbl+yNMLYME0 码力 | 81 页 | 13.18 MB | 1 年前3《Efficient Deep Learning Book》[EDL] Chapter 5 - Advanced Compression Techniques
notebook here. %%capture import gzip import operator, random import numpy as np import tensorflow as tf from functools import reduce from matplotlib import pyplot as plt We define two functions sparsify_smallest() (x) and the # centroids. distances = tf.subtract(tf.reshape(x_var, (-1, 1)), centroids_var) ** 2 best_distances = tf.math.reduce_min(distances, axis=1) return tf.reduce_mean(best_distances) Now we can it is not trainable. x_var = tf.Variable(initial_value=x_sorted, trainable=False) # The centroids are going to be updated, thus they will be trainable. centroids_var = tf.Variable(initial_value=centroids_init0 码力 | 34 页 | 3.18 MB | 1 年前3《TensorFlow 2项目进阶实战》2-快速上手篇:动⼿训练模型和部署服务
《TensorFlow 2 项目进阶实战》视频课程 快速上手篇:动⼿训练模型和部署服务 • TensorFlow 2 开发环境搭建 • 使用 tf.keras.datasets 加载数据 • 使用 tf.data.Dataset 加载数据 • 使用 tf.keras.Model 管理模型 • Fashion MNIST 数据集介绍 • 使用 TensorFlow 2 训练分类网络 目录 TensorFlow” Try it! 使用 tf.keras.datasets 加载数据 使用 tf.keras.datasets 预置数据集 使用 tf.keras.datasets.mnist 数据集 使用 tf.keras.datasets.mnist 数据集 “Hello TensorFlow” Try it! 使用 tf.data.Dataset 加载数据 使用 tf.data.Dataset from_tensor_slices 加载 List 使用 tf.data.Dataset.from_generator 加载 Generator 使用 tf.data.TextLineDataset 加载文本 “Hello TensorFlow” Try it! 使用 tf.keras.Model 管理模型 历史上的 tf.keras.Model • Class tf.compat.v1.keras.Model0 码力 | 52 页 | 7.99 MB | 1 年前3《Efficient Deep Learning Book》[EDL] Chapter 6 - Advanced Learning Techniques - Technical Review
tensorflow_datasets as tfds with tf.device('/job:localhost'): ds = tfds.load('ag_news_subset', try_gcs=True, shuffle_files=True, batch_size=-1) train_dataset = tf.data.Dataset.from_tensor_slices(ds['train']) s['train']) test_dataset = tf.data.Dataset.from_tensor_slices(ds['test']) As usual, we will start off by creating our training and test datasets. BATCH_SIZE = 256 batched_train = train_dataset.shuffle(train_dataset tensorflow_text is required so that we can use certain ops used in our model. import tensorflow_text as tf_text Next we will import the tensorflow_hub library so that we can import pre-trained BERT models0 码力 | 31 页 | 4.03 MB | 1 年前3
共 313 条
- 1
- 2
- 3
- 4
- 5
- 6
- 32