Home | History | Annotate | Download | only in ops
      1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include "tensorflow/core/framework/common_shape_fns.h"
     17 #include "tensorflow/core/framework/op.h"
     18 #include "tensorflow/core/framework/shape_inference.h"
     19 
     20 namespace tensorflow {
     21 
     22 using shape_inference::InferenceContext;
     23 
     24 REGISTER_OP("DecodeLibsvm")
     25     .Input("input: string")
     26     .Output("label: label_dtype")
     27     .Output("feature_indices: int64")
     28     .Output("feature_values: dtype")
     29     .Output("feature_shape: int64")
     30     .Attr("dtype: {float, double, int32, int64} = DT_FLOAT")
     31     .Attr("label_dtype: {float, double, int32, int64} = DT_INT64")
     32     .Attr("num_features: int >= 1")
     33     .SetShapeFn([](InferenceContext* c) {
     34       c->set_output(0, c->input(0));
     35 
     36       c->set_output(1, c->Matrix(InferenceContext::kUnknownDim,
     37                                  InferenceContext::kUnknownDim));
     38       c->set_output(2, c->Vector(InferenceContext::kUnknownDim));
     39       c->set_output(3, c->Vector(InferenceContext::kUnknownDim));
     40 
     41       return Status::OK();
     42     })
     43 
     44     .Doc(R"doc(
     45 Convert LibSVM input to tensors. The output consists of
     46 a label and a feature tensor. The shape of the label tensor
     47 is the same as input and the shape of the feature tensor is
     48 `[input_shape, num_features]`.
     49 
     50 input: Each string is a record in the LibSVM.
     51 label: A tensor of the same shape as input.
     52 feature_indices: A 2-D int64 tensor of dense_shape [N, ndims].
     53 feature_values: A 1-D tensor of any type and dense_shape [N].
     54 feature_shape: A 1-D int64 tensor of dense_shape [ndims].
     55 num_features: The number of features.
     56 )doc");
     57 
     58 }  // namespace tensorflow
     59