@@ -19,6 +19,7 @@ limitations under the License.
1919using System . Linq ;
2020using static Tensorflow . OpDef . Types ;
2121using static Tensorflow . Binding ;
22+ using Google . Protobuf ;
2223
2324namespace Tensorflow
2425{
@@ -194,7 +195,9 @@ public Operation _apply_op_helper(string op_type_name, string name = null, Dicti
194195 if ( attrs . ContainsKey ( key ) )
195196 {
196197 attr_protos [ key ] = SetAttrValue ( op_def , attr_def , attrs [ key ] ) ;
197- } else {
198+ }
199+ else
200+ {
198201 if ( attr_def . DefaultValue == null )
199202 {
200203 throw new TypeError ( "Missing required positional argument " + key ) ;
@@ -311,6 +314,16 @@ private void SetAttrs(string op_type_name,
311314 input_types . AddRange ( base_types ) ;
312315 }
313316
317+ public ByteString _MakeStr ( string value , AttrDef attr_def )
318+ {
319+ return ByteString . CopyFromUtf8 ( value ?? string . Empty ) ;
320+ }
321+
322+ public TensorShapeProto _MakeShape ( TensorShape shape , AttrDef attr_def )
323+ {
324+ return shape . as_proto ( ) ;
325+ }
326+
314327 public DataType _MakeType ( TF_DataType v , AttrDef attr_def )
315328 {
316329 return v . as_base_dtype ( ) . as_datatype_enum ( ) ;
@@ -330,7 +343,7 @@ private AttrValue SetAttrValue(OpDef op_def, AttrDef attr_def, object value)
330343 switch ( attr_def . Type )
331344 {
332345 case "string" :
333- attr_value . S = Google . Protobuf . ByteString . CopyFromUtf8 ( ( string ) value ) ;
346+ attr_value . S = _MakeStr ( ( string ) value , attr_def ) ;
334347 break ;
335348 case "type" :
336349 attr_value . Type = _MakeType ( ( TF_DataType ) value , attr_def ) ;
@@ -363,6 +376,9 @@ private AttrValue SetAttrValue(OpDef op_def, AttrDef attr_def, object value)
363376 else if ( value is int [ ] val3 )
364377 attr_value . Shape = tensor_util . as_shape ( val3 ) ;
365378
379+ break ;
380+ case "list(shape)" :
381+ attr_value . List . Shape . AddRange ( ( value as TensorShape [ ] ) . Select ( x => _MakeShape ( x , attr_def ) ) ) ;
366382 break ;
367383 default :
368384 throw new TypeError ( $ "SetAttrValue: can't not convert attr_def.Type '{ attr_def . Type } ' to protos.") ;
0 commit comments