具有TensorFlow服务的Tensorflow固定估计器模型

时间:2018-12-28 14:15:43

标签: tensorflow tensorflow-serving

我想导出固定估计器模型以与tensorflow服务一起使用,但是我看到的例子是我们必须声明 serving_input_receiver_fn 。 示例如下:

// Add event listener for opening and closing details
$('#example tbody').on('click', 'td.details-control', function () {
    var tr = $(this).closest('tr');
    var row = table.row( tr );

    if ( row.child.isShown() ) {
        // This row is already open - close it
        $('div.slider', row.child()).slideUp( function () {
            row.child.hide();
            tr.removeClass('shown');
        } );
    }
    else {
        // Open this row
        row.child( format(row.data()), 'no-padding' ).show();
        tr.addClass('shown');

        $('div.slider', row.child()).slideDown();
    }
} );

我遵循了这个示例,我的代码是这样的:

 $('#submit').click(function() {    
        fire_ajax_submit();
});

function fire_ajax_submit() {
    // PREPARE FORM DATA
    var formData = {
        username  : $("#username").val(),
        password  :  $("#password").val()

    }

    var protocol = window.location.protocol;
    var host = window.location.host;
    var pathArray = window.location.pathname.split('/');
    var pathName = pathArray[1];
    $.ajax({
        type : "POST",
        contentType : "application/json",
        url : protocol + "//" + host + "/" + pathName + "/auth/signin",
        data : JSON.stringify(formData),
        dataType : 'json',
        cache : false,
        success : function(data) {
            //doSomthing

        },
        error : function(e) {
            console.log("ERROR : ", e);         

        }
    });

}

我模型的输入是:

feature_spec = {'foo': tf.FixedLenFeature(...),
                'bar': tf.VarLenFeature(...)}

def serving_input_receiver_fn():
  """An input receiver that expects a serialized tf.Example."""
  serialized_tf_example = tf.placeholder(dtype=tf.string,
                                         shape=[default_batch_size],
                                         name='input_example_tensor')
  receiver_tensors = {'examples': serialized_tf_example}
  features = tf.parse_example(serialized_tf_example, feature_spec)
  return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)

错误是:

feature_spec = {'user_id': tf.FixedLenFeature([1], tf.int64),
                    'item_id': tf.FixedLenFeature([1], tf.int64),}

def serving_input_receiver_fn():
   serialized_tf_example = tf.placeholder(dtype=tf.string, shape=[None], name='input_tensors')
   receiver_tensors = {'inputs': serialized_tf_example}

   features = tf.parse_example(serialized_tf_example, feature_spec)

   return tf.estimator.export.ServingInputReceiver(features, receiver_tensors)

0 个答案:

没有答案