PFLD
PFLD copied to clipboard
mat_ratio = tf.map_fn(lambda x:(tf.cond(x > 0,lambda: 1/x,lambda:float(args.batch_size))),mat_ratio)
so damn hard to understand. can someone help me~~~~~~~~
that is : if mat_ratio > 0 then mat_ratio = 1/mat_ratio else mat_ratio = args.batch_size
the function tf.cond needs 3 parameters: condition, func1, func2 and if condition is true it return func1 ,otherwise func2 Here, 'x>0' is condition, 'lambda: 1/x' is func1 and 'lambda:float(args.batch_size)' is func2
and tf.map_fn need 2 parameters: function and its parameters list the first lambda expression (lambda x: ... ) is just the function and the variable 'mat_ratio' is just the parameter list. Because the function 'lambda x: ...' needs only one parameter, the parameter list needed by 'tf.map_fn' is the single parameter 'mat_ratio' rather than a list
that is : if mat_ratio > 0 then mat_ratio = 1/mat_ratio else mat_ratio = args.batch_size
the function tf.cond needs 3 parameters: condition, func1, func2 and if condition is true it return func1 ,otherwise func2 Here, 'x>0' is condition, 'lambda: 1/x' is func1 and 'lambda:float(args.batch_size)' is func2
and tf.map_fn need 2 parameters: function and its parameters list the first lambda expression (lambda x: ... ) is just the function and the variable 'mat_ratio' is just the parameter list. Because the function 'lambda x: ...' needs only one parameter, the parameter list needed by 'tf.map_fn' is the single parameter 'mat_ratio' rather than a list
thanks a lot,pal