1 /* Copyright 2015 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/dataset_stateful_op_whitelist.h" 18 #include "tensorflow/core/framework/op.h" 19 #include "tensorflow/core/framework/shape_inference.h" 20 21 namespace tensorflow { 22 23 using shape_inference::InferenceContext; 24 25 REGISTER_OP("Assert") 26 .Input("condition: bool") 27 .Input("data: T") 28 .SetIsStateful() 29 .Attr("T: list(type)") 30 .Attr("summarize: int = 3") 31 .SetShapeFn(shape_inference::NoOutputs); 32 33 WHITELIST_STATEFUL_OP_FOR_DATASET_FUNCTIONS("Assert"); 34 35 REGISTER_OP("Print") 36 .Input("input: T") 37 .Input("data: U") 38 .Output("output: T") 39 .SetIsStateful() 40 .Attr("T: type") 41 .Attr("U: list(type) >= 0") 42 .Attr("message: string = ''") 43 .Attr("first_n: int = -1") 44 .Attr("summarize: int = 3") 45 .SetShapeFn(shape_inference::UnchangedShape); 46 47 WHITELIST_STATEFUL_OP_FOR_DATASET_FUNCTIONS("Print"); 48 49 REGISTER_OP("PrintV2") 50 .Input("input: string") 51 .SetIsStateful() 52 .Attr("output_stream: string = 'stderr'") __anona48932a30102(InferenceContext* c) 53 .SetShapeFn([](InferenceContext* c) { 54 // Make sure that the input is a scalar. 55 if (c->Rank(c->input(0)) != 0) { 56 return errors::InvalidArgument("input must be a scalar, but has rank: ", 57 c->Rank(c->input(0))); 58 } 59 return Status::OK(); 60 }); 61 62 WHITELIST_STATEFUL_OP_FOR_DATASET_FUNCTIONS("PrintV2"); 63 64 // ---------------------------------------------------------------------------- 65 // Operators that deal with SummaryProtos (encoded as DT_STRING tensors) as 66 // inputs or outputs in various ways. 67 68 REGISTER_OP("TensorSummaryV2") 69 .Input("tag: string") 70 .Input("tensor: T") 71 // This serialized summary metadata field describes a summary value, 72 // specifically which plugins may use that summary. 73 .Input("serialized_summary_metadata: string") 74 .Output("summary: string") 75 .Attr("T: type") 76 .SetShapeFn(shape_inference::ScalarShape); 77 78 REGISTER_OP("TensorSummary") 79 .Input("tensor: T") 80 .Output("summary: string") 81 .Attr("T: type") 82 .Attr("description: string = ''") 83 .Attr("labels: list(string) = []") 84 .Attr("display_name: string = ''") 85 .SetShapeFn(shape_inference::ScalarShape); 86 87 REGISTER_OP("ScalarSummary") 88 .Input("tags: string") 89 .Input("values: T") 90 .Output("summary: string") 91 .Attr("T: realnumbertype") 92 .SetShapeFn(shape_inference::ScalarShape); 93 94 REGISTER_OP("HistogramSummary") 95 .Input("tag: string") 96 .Input("values: T") 97 .Output("summary: string") 98 .Attr("T: realnumbertype = DT_FLOAT") 99 .SetShapeFn(shape_inference::ScalarShape); 100 101 REGISTER_OP("ImageSummary") 102 .Input("tag: string") 103 .Input("tensor: T") 104 .Output("summary: string") 105 .Attr("max_images: int >= 1 = 3") 106 .Attr("T: {uint8, float, half, float64} = DT_FLOAT") 107 .Attr( 108 "bad_color: tensor = { dtype: DT_UINT8 " 109 "tensor_shape: { dim { size: 4 } } " 110 "int_val: 255 int_val: 0 int_val: 0 int_val: 255 }") 111 .SetShapeFn(shape_inference::ScalarShape); 112 113 REGISTER_OP("AudioSummaryV2") 114 .Input("tag: string") 115 .Input("tensor: float") 116 .Input("sample_rate: float") 117 .Output("summary: string") 118 .Attr("max_outputs: int >= 1 = 3") 119 .SetShapeFn(shape_inference::ScalarShape); 120 121 REGISTER_OP("AudioSummary") 122 .Input("tag: string") 123 .Input("tensor: float") 124 .Output("summary: string") 125 .Attr("sample_rate: float") 126 .Attr("max_outputs: int >= 1 = 3") 127 .SetShapeFn(shape_inference::ScalarShape) 128 .Deprecated(15, "Use AudioSummaryV2."); 129 130 REGISTER_OP("MergeSummary") 131 .Input("inputs: N * string") 132 .Output("summary: string") 133 .Attr("N : int >= 1") 134 .SetShapeFn(shape_inference::ScalarShape); 135 136 REGISTER_OP("Timestamp") 137 .Output("ts: float64") 138 .SetIsStateful() 139 .SetShapeFn(shape_inference::ScalarShape); 140 141 WHITELIST_STATEFUL_OP_FOR_DATASET_FUNCTIONS("Timestamp"); 142 143 } // end namespace tensorflow 144