def _call_cntk(self, config_file_name, config_content, action_name): ''' Calls the CNTK executable on the `config_content`. Args: config_file_name (str): the name of the configuration file config_content (str): a string containing the configuration action_name (str): the name of the action in cntk configuration file Returns: the output generated by the CNTK executable, which is used to retrieve the node shapes. ''' filename = self._save_file(config_file_name, config_content, action_name) try: output_bytes = subprocess.check_output( [get_cntk_cmd(), 'configFile=%s' % filename], stderr=subprocess.STDOUT) output = output_bytes.decode('utf-8') with open(os.path.join(self.directory, 'cntk.log'), 'w') as log: log.write(output) except subprocess.CalledProcessError as e: with open('error.txt', 'w') as f: f.write(e.output.decode('utf-8')) print("=" * 50) print(e.output.decode('utf-8')) print("=" * 50) raise if not output: raise ValueError('no output returned') return output
def _call_cntk(self, config_file_name, config_content): ''' Calls the CNTK exe :param config_file_name: the name of the configuration file :param config_content: a string containing the configuration Returns the output generated by the CNTK executable, which is used to retrieve the node shapes. ''' filename = os.path.join(self.directory, config_file_name) with open(os.path.join(self.directory, filename), 'w') as out: out.write(config_content) try: output_bytes = subprocess.check_output( [get_cntk_cmd(), 'configFile=%s' % filename], stderr=subprocess.STDOUT) output = output_bytes.decode('utf-8') with open(os.path.join(self.directory, 'cntk.log'), 'w') as log: log.write(output) except subprocess.CalledProcessError as e: print(e.output.decode('utf-8'), file=open('error.txt', 'w')) raise if not output: raise ValueError('no output returned') return output