Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

A question about recall other function from other Python.file #81

Open
Lan1991Xu opened this issue Jan 13, 2017 · 7 comments
Open

A question about recall other function from other Python.file #81

Lan1991Xu opened this issue Jan 13, 2017 · 7 comments

Comments

@Lan1991Xu
Copy link

Lan1991Xu commented Jan 13, 2017

Hi, I meet some problem when I want receive some information from about the train function .
this is main function in main.py:

import tensorflow as tf
from dqn.agent import Agent
from config import Config
@profile
def main(args):
	with tf.device('/gpu:0'):
		config = tf.ConfigProto(allow_soft_placement = True)
		with tf.Session(config = config) as sess:
			config = Config() 
			player = Agent(config, sess)
			if config.isTrain:
				player.train()
			else:
				player.play() 
if __name__ == '__main__':
	tf.app.run()

This is another function named agent:

Class Agent(BaseModel):
          .....
           @profile 
    def train(self):
        # timer
        st = time.time()
        if self.isLoadFromModel:
            self.load_model()
        else:
            self.sess.run(tf.initialize_all_variables())
            self.update_target_net()
         .....

The output is:

Wrote profile results to main.py.lprof
Timer unit:1 e-06s
File: main.py
Function: main at line 6

When I run kernprof - l -v main.py, it can not print the time of train function line by line, only the information about the each line running time in main.py. I want to know is there some misunderstanding about the line_profile. Thanks

@Lan1991Xu
Copy link
Author

Is the problem caused by Class agent?

@rkern
Copy link
Owner

rkern commented Jan 14, 2017

Can you reduce this to a complete minimal example that the rest of us can run? And format it so that the indentation is preserved? Thanks.

If I had to guess, tensorflow is starting a subprocess that runs the code that you want to profile. tensorflow might have a configuration to run everything in the same process; I don't know.

@Lan1991Xu
Copy link
Author

Hi rkern
The problem is still confused me. When I run it in some complete minimal example, it works. However,the original examples still not work. i just pack this documents in dropbox https://www.dropbox.com/sh/9o259gcw187sn1o/AAD3FpRpzjTO5rucrp-RLV1Za?dl=0
There is four documents. The simple one is main1.py agent1.py. Which I call agent1.py(training function) and want to get the detail of agent1.py. It works, while the orginal one does not work. So I think this may not be the problem of Tensorflow. But what actually the problem is still not solved

@Lan1991Xu
Copy link
Author

Hi Rkern
Sorry, I think these problem is still exist in main1.py and agent.py. It can derectly run it, but there is no Hit Tim Per Hit %time number. I don't why?

@rkern
Copy link
Owner

rkern commented Jan 15, 2017

The problem is still likely to be tf.app.run().

@Lan1991Xu
Copy link
Author

Yes, I solve it. Thanks

@mpariente
Copy link

@Lan1991Xu : How did you solve it?

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

No branches or pull requests

3 participants