在Tensor类中核心为 TensorShape shape_与TensorBuffer* buf_两个变量.
其中TensorShape类继承与TensorShapeBase<TensorShape> 这个是一个模板类,而TensorShapeBase类继承与TensorShapeRep类.TensorShapeRep是TensorShape的爷爷,TensorShapeBase是TensorShape的爸爸.....
其中爷爷类TensorShapeRep(tensor_shape.h),定义如下:
class TensorShapeRep {
public:
~TensorShapeRep();
//拷贝构造、赋值构造、右值引用、移动构造
TensorShapeRep(const TensorShapeRep& b);
void operator=(const TensorShapeRep& b);
TensorShapeRep(TensorShapeRep&& b);
void operator=(TensorShapeRep&& b);
/// Clear a tensor shape, producing the scalar shape.
void Clear();
static constexpr int MaxDimensions() { return 254; }//最大维度为254维,255表示未知维度
int64 num_elements() const { return
本文详细介绍了TensorFlow中TensorShape类的设计,包括其内部结构、维度存储方式以及与TensorShapeBase和TensorShapeRep的关系。TensorShapeRep使用16字节存储信息,提供不同维度存储格式,并通过TensorShapeBase增加操作接口和迭代器。TensorShape类在基础上实现主要功能,而PartialTensorShape用于处理不确定维度的形状,常在神经网络层间操作中使用。
订阅专栏 解锁全文
612

被折叠的 条评论
为什么被折叠?



