如何解决Tensorflow中的RuntimeShape :: ExtendedShape
查看Tensorflow的SparseToDense操作。 它有
const RuntimeShape output_shape = RuntimeShape::ExtendedShape(4,unextended_output_shape);
我在哪里可以知道RuntimeShape::ExtendedShape
的工作方式?
输入unextended_output_shape
看起来如何?
整个代码如下。
void SparseToDense(const std::vector<std::vector<int>>& indices,const float* values,float default_value,bool value_is_scalar,const RuntimeShape& unextended_output_shape,float* output_data) {
//TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(),4);
const RuntimeShape output_shape = RuntimeShape::ExtendedShape(4,unextended_output_shape);
const int value_count = indices.size();
// First fill the output_data with default value.
const int num_elements = output_shape.FlatSize();
for (int i = 0; i < num_elements; ++i) {
output_data[i] = default_value;
}
// Special handle for value is scalar case to avoid checking the boolean
// condition within the loop every time.
if (value_is_scalar) {
for (int i = 0; i < value_count; ++i) {
const std::vector<int>& index = indices[i];
if(index.size()<4)
cout<<"index.size()<4"<<endl;
const float value = *values; // just use the first value.
output_data[Offset(output_shape,index[0],index[1],index[2],index[3])] = value;
}
return;
}
// Go through the values and indices to fill the sparse values.
for (int i = 0; i < value_count; ++i) {
const std::vector<int>& index = indices[i];
if(index.size()<4)
cout<<"index.size()<4"<<endl;
const float value = values[i];
output_data[Offset(output_shape,index[3])] = value;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。