Python os.makedirs方法程式碼示例
阿新 • • 發佈:2020-12-28
本文整理Python中os.makedirs方法的典型用法程式碼示例
示例1: save_to_path
# 需要匯入模組: import os [as 別名] # 或者: from os import makedirs [as 別名] def save_to_path(self, filepath): """Save retrieved data to file at ``filepath``. .. versionadded: 1.9.6 :param filepath: Path to save retrieved data. """ filepath = os.path.abspath(filepath) dirname = os.path.dirname(filepath) if not os.path.exists(dirname): os.makedirs(dirname) self.stream = True with open(filepath, 'wb') as fileobj: for data in self.iter_content(): fileobj.write(data)
示例2: savepb
# 需要匯入模組: import os [as 別名] # 或者: from os import makedirs [as 別名] def savepb(self): """ Create a standalone const graph def that C++ can load and run. """ darknet_pb = self.to_darknet() flags_pb = self.FLAGS flags_pb.verbalise = False flags_pb.train = False # rebuild another tfnet. all const. tfnet_pb = TFNet(flags_pb, darknet_pb) tfnet_pb.sess = tf.Session(graph = tfnet_pb.graph) # tfnet_pb.predict() # uncomment for unit testing name = 'built_graph/{}.pb'.format(self.meta['name']) os.makedirs(os.path.dirname(name), exist_ok=True) #Save dump of everything in meta with open('built_graph/{}.meta'.format(self.meta['name']), 'w') as fp: json.dump(self.meta, fp) self.say('Saving const graph def to {}'.format(name)) graph_def = tfnet_pb.sess.graph_def tf.train.write_graph(graph_def,'./', name, False)