PFLD icon indicating copy to clipboard operation
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)

Open jiangtaoo2333 opened this issue 5 years ago • 2 comments

so damn hard to understand. can someone help me~~~~~~~~

jiangtaoo2333 avatar Oct 24 '19 08:10 jiangtaoo2333

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

sljlp avatar Dec 04 '19 05:12 sljlp

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

jiangtaoo2333 avatar Dec 13 '19 02:12 jiangtaoo2333