问题描述
查看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 (将#修改为@)