Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mat_ratio = tf.map_fn(lambda x:(tf.cond(x > 0,lambda: 1/x,lambda:float(args.batch_size))),mat_ratio) #64

Open
jiangtaoo2333 opened this issue Oct 24, 2019 · 2 comments

Comments

@jiangtaoo2333
Copy link

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

@sljlp
Copy link

sljlp commented Dec 4, 2019

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

@jiangtaoo2333
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants