Python tensorflow.gfile.Exists() Examples
The following are 30
code examples of tensorflow.gfile.Exists().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow.gfile
, or try the search function
.
Example #1
Source File: vocabulary.py From transformer-xl-chinese with Apache License 2.0 | 6 votes |
def count_file(self, path, verbose=False, add_eos=False): if verbose: print('counting file {} ...'.format(path)) assert exists(path) sents = [] with open(path, 'r') as f: for idx, line in enumerate(f): if verbose and idx > 0 and idx % 500000 == 0: print(' line {}'.format(idx)) symbols = self.tokenize(line, add_eos=True) self.counter.update(symbols) sents.append(symbols) return sents # 更新counter 中的token
Example #2
Source File: misc.py From NJUNMT-tf with Apache License 2.0 | 6 votes |
def access_multiple_files(name): """ Gets the list of files. Args: name: A string, the prefix of the files. Returns: A list or None. """ assert name ret = [] if gfile.Exists(name): ret.append(name) else: idx = 0 while gfile.Exists(name + str(idx)): ret.append(name + str(idx)) idx += 1 assert len(ret) > 0, ( "Fail to access file {} or {}0...".format(name, name)) return ret
Example #3
Source File: train.py From NJUNMT-tf with Apache License 2.0 | 6 votes |
def main(_argv): # load flags from config file model_configs = load_from_config_path(FLAGS.config_paths) # replace parameters in configs_file with tf FLAGS model_configs = update_configs_from_flags(model_configs, FLAGS, TRAIN_ARGS.keys()) model_dir = model_configs["model_dir"] if not gfile.Exists(model_dir): gfile.MakeDirs(model_dir) if "CUDA_VISIBLE_DEVICES" not in os.environ.keys(): raise OSError("need CUDA_VISIBLE_DEVICES environment variable") tf.logging.info("CUDA_VISIBLE_DEVICES={}".format(os.environ["CUDA_VISIBLE_DEVICES"])) training_runner = TrainingExperiment( model_configs=model_configs) training_runner.run()
Example #4
Source File: train.py From youtube8mchallenge with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #5
Source File: train_distill.py From youtube8mchallenge with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #6
Source File: data_utils.py From transformer-xl with Apache License 2.0 | 6 votes |
def main(unused_argv): del unused_argv # Unused corpus = get_lm_corpus(FLAGS.data_dir, FLAGS.dataset) save_dir = os.path.join(FLAGS.data_dir, "tfrecords") if not exists(save_dir): makedirs(save_dir) # test mode if FLAGS.per_host_test_bsz > 0: corpus.convert_to_tfrecords("test", save_dir, FLAGS.per_host_test_bsz, FLAGS.tgt_len, FLAGS.num_core_per_host, FLAGS=FLAGS) return for split, batch_size in zip( ["train", "valid"], [FLAGS.per_host_train_bsz, FLAGS.per_host_valid_bsz]): if batch_size <= 0: continue print("Converting {} set...".format(split)) corpus.convert_to_tfrecords(split, save_dir, batch_size, FLAGS.tgt_len, FLAGS.num_core_per_host, FLAGS=FLAGS)
Example #7
Source File: configurable.py From NJUNMT-tf with Apache License 2.0 | 6 votes |
def load_from_config_path(config_paths): """ Loads configurations from files of yaml format. Args: config_paths: A string (each file name is seperated by ",") or a list of strings (file names). Returns: A dictionary of model configurations, parsed from config files. """ if isinstance(config_paths, six.string_types): config_paths = config_paths.strip().split(",") assert isinstance(config_paths, list) or isinstance(config_paths, tuple) model_configs = dict() for config_path in config_paths: config_path = config_path.strip() if not config_path: continue if not gfile.Exists(config_path): raise OSError("config file does not exist: {}".format(config_path)) config_path = os.path.abspath(config_path) tf.logging.info("loading configurations from {}".format(config_path)) with open_file(config_path, mode="r") as config_file: config_flags = yaml.load(config_file) model_configs = deep_merge_dict(model_configs, config_flags) return model_configs
Example #8
Source File: vocabulary.py From transformer-xl with Apache License 2.0 | 6 votes |
def encode_file(self, path, ordered=False, verbose=False, add_eos=True, add_double_eos=False): if verbose: print('encoding file {} ...'.format(path)) assert exists(path) encoded = [] with open(path, 'r') as f: for idx, line in enumerate(f): if verbose and idx > 0 and idx % 500000 == 0: print(' line {}'.format(idx)) symbols = self.tokenize(line, add_eos=add_eos, add_double_eos=add_double_eos) encoded.append(self.convert_to_nparray(symbols)) if ordered: encoded = np.concatenate(encoded) return encoded
Example #9
Source File: data_utils_chinese.py From transformer-xl-chinese with Apache License 2.0 | 6 votes |
def main(unused_argv): del unused_argv # Unused corpus = get_lm_corpus(FLAGS.data_dir, FLAGS.dataset) # save_dir = os.path.join(FLAGS.data_dir, "tfrecords") if not exists(save_dir): makedirs(save_dir) # test mode if FLAGS.per_host_test_bsz > 0: corpus.convert_to_tfrecords("test", save_dir, FLAGS.per_host_test_bsz, FLAGS.tgt_len, FLAGS.num_core_per_host, FLAGS=FLAGS) return for split, batch_size in zip( ["train", "valid"], [FLAGS.per_host_train_bsz, FLAGS.per_host_valid_bsz]): if batch_size <= 0: continue print("Converting {} set...".format(split)) corpus.convert_to_tfrecords(split, save_dir, batch_size, FLAGS.tgt_len, FLAGS.num_core_per_host, FLAGS=FLAGS)
Example #10
Source File: train.py From AttentionCluster with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #11
Source File: old_vocabulary.py From transformer-xl-chinese with Apache License 2.0 | 6 votes |
def count_file(self, path, verbose=False, add_eos=False): if verbose: print('counting file {} ...'.format(path)) assert exists(path) sents = [] with open(path, 'r') as f: for idx, line in enumerate(f): if verbose and idx > 0 and idx % 500000 == 0: print(' line {}'.format(idx)) symbols = self.tokenize(line, add_eos=add_eos) self.counter.update(symbols) sents.append(symbols) return sents # 更新counter 中的token
Example #12
Source File: data_utils.py From transformer-xl-chinese with Apache License 2.0 | 6 votes |
def main(unused_argv): del unused_argv # Unused corpus = get_lm_corpus(FLAGS.data_dir, FLAGS.dataset) # save_dir = os.path.join(FLAGS.data_dir, "tfrecords") if not exists(save_dir): makedirs(save_dir) # test mode if FLAGS.per_host_test_bsz > 0: corpus.convert_to_tfrecords("test", save_dir, FLAGS.per_host_test_bsz, FLAGS.tgt_len, FLAGS.num_core_per_host, FLAGS=FLAGS) return for split, batch_size in zip( ["train", "valid"], [FLAGS.per_host_train_bsz, FLAGS.per_host_valid_bsz]): if batch_size <= 0: continue print("Converting {} set...".format(split)) corpus.convert_to_tfrecords(split, save_dir, batch_size, FLAGS.tgt_len, FLAGS.num_core_per_host, FLAGS=FLAGS)
Example #13
Source File: train.py From Y8M with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #14
Source File: vocabulary.py From transformer-xl-chinese with Apache License 2.0 | 6 votes |
def encode_file(self, path, ordered=False, verbose=False, add_double_eos=False): if verbose: print('encoding file {} ...'.format(path)) assert exists(path) encoded = [] with open(path, 'r') as f: for idx, line in enumerate(f): if verbose and idx > 0 and idx % 500000 == 0: print(' line {}'.format(idx)) symbols = self.tokenize(line, add_eos=True, add_double_eos=add_double_eos) encoded.append(self.convert_to_nparray(symbols)) if ordered: encoded = np.concatenate(encoded) return encoded #
Example #15
Source File: train.py From youtube-8m with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #16
Source File: train.py From youtube-8m with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #17
Source File: train-with-predictions.py From youtube-8m with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #18
Source File: train_autoencoder.py From youtube-8m with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #19
Source File: train_embedding.py From youtube-8m with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #20
Source File: train-with-rebuild.py From youtube-8m with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #21
Source File: train_ensemble.py From youtube-8m with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #22
Source File: train.py From youtube-8m with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #23
Source File: train.py From Y8M with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #24
Source File: train.py From Youtube-8M-WILLOW with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #25
Source File: run_inference.py From ffn with Apache License 2.0 | 6 votes |
def main(unused_argv): request = inference_flags.request_from_flags() if not gfile.Exists(request.segmentation_output_dir): gfile.MakeDirs(request.segmentation_output_dir) bbox = bounding_box_pb2.BoundingBox() text_format.Parse(FLAGS.bounding_box, bbox) runner = inference.Runner() runner.start(request) runner.run((bbox.start.z, bbox.start.y, bbox.start.x), (bbox.size.z, bbox.size.y, bbox.size.x)) counter_path = os.path.join(request.segmentation_output_dir, 'counters.txt') if not gfile.Exists(counter_path): runner.counters.dump(counter_path)
Example #26
Source File: train.py From Y8M with Apache License 2.0 | 6 votes |
def get_meta_filename(self, start_new_model, train_dir): if start_new_model: logging.info("%s: Flag 'start_new_model' is set. Building a new model.", task_as_string(self.task)) return None latest_checkpoint = tf.train.latest_checkpoint(train_dir) if not latest_checkpoint: logging.info("%s: No checkpoint file found. Building a new model.", task_as_string(self.task)) return None meta_filename = latest_checkpoint + ".meta" if not gfile.Exists(meta_filename): logging.info("%s: No meta graph file found. Building a new model.", task_as_string(self.task)) return None else: return meta_filename
Example #27
Source File: data_iterator.py From NJUNMT-tf with Apache License 2.0 | 5 votes |
def __init__(self, source, target, vocab_source, vocab_target, batch_size=128, n_words_src=-1, n_words_trg=-1): # read in batch datas f_source = open_file(source) if gfile.Exists(target): f_target = open_file(target) else: f_target = open_file(target + "0") ss_buf = [] tt_buf = [] for ss, tt in zip(f_source, f_target): ss = vocab_source.convert_to_idlist(ss.strip().split(), n_words_src) tt = vocab_target.convert_to_idlist(tt.strip().split(), n_words_trg) ss_buf.append(ss) tt_buf.append(tt) f_source.close() f_target.close() tlen = numpy.array([len(t) for t in tt_buf]) tidx = tlen.argsort() _ss_buf = [ss_buf[i] for i in tidx] _tt_buf = [tt_buf[i] for i in tidx] ss_buf = _ss_buf tt_buf = _tt_buf self.batch_source_buffer = [] self.batch_target_buffer = [] self.batch_data_idx = 0 self.batch_size = batch_size while self.batch_data_idx < len(ss_buf): self.batch_source_buffer.append( padding_batch_data(ss_buf[self.batch_data_idx: self.batch_data_idx + batch_size], vocab_source.eos_id)) self.batch_target_buffer.append( padding_batch_data(tt_buf[self.batch_data_idx: self.batch_data_idx + batch_size], vocab_target.eos_id)) self.batch_data_idx += batch_size self.reset()
Example #28
Source File: profile.py From reaction_prediction_seq2seq with Apache License 2.0 | 5 votes |
def load_metadata(model_dir): """Loads RunMetadata, Graph and OpLog from files """ # Import RunMetadata run_meta_path = os.path.join(model_dir, "metadata/run_meta") run_meta = tf.RunMetadata() if gfile.Exists(run_meta_path): with gfile.GFile(run_meta_path, "rb") as file: run_meta.MergeFromString(file.read()) print("Loaded RunMetadata from {}".format(run_meta_path)) else: print("RunMetadata does not exist a {}. Skipping.".format(run_meta_path)) # Import Graph graph_def_path = os.path.join(model_dir, "graph.pbtxt") graph = tf.Graph() if gfile.Exists(graph_def_path): with graph.as_default(): _register_function_ops(CUSTOM_OP_FUNCTIONS) graph_def = tf.GraphDef() with gfile.GFile(graph_def_path, "rb") as file: text_format.Parse(file.read(), graph_def) tf.import_graph_def(graph_def, name="") print("Loaded Graph from {}".format(graph_def_path)) else: print("Graph does not exist a {}. Skipping.".format(graph_def_path)) # Import OpLog op_log_path = os.path.join(model_dir, "metadata/tfprof_log") op_log = tfprof_log_pb2.OpLog() if gfile.Exists(op_log_path): with gfile.GFile(op_log_path, "rb") as file: op_log.MergeFromString(file.read()) print("Loaded OpLog from {}".format(op_log_path)) else: print("OpLog does not exist a {}. Skipping.".format(op_log_path)) return run_meta, graph, op_log
Example #29
Source File: utils.py From professional-services with Apache License 2.0 | 5 votes |
def dump_object(object_to_dump, output_path): """Pickle the object and save to the output_path. Args: object_to_dump: Python object to be pickled output_path: (string) output path which can be Google Cloud Storage Returns: None """ if not gfile.Exists(output_path): gfile.MakeDirs(os.path.dirname(output_path)) with gfile.Open(output_path, 'w') as wf: joblib.dump(object_to_dump, wf)
Example #30
Source File: profile.py From seq2seq with Apache License 2.0 | 5 votes |
def load_metadata(model_dir): """Loads RunMetadata, Graph and OpLog from files """ # Import RunMetadata run_meta_path = os.path.join(model_dir, "metadata/run_meta") run_meta = tf.RunMetadata() if gfile.Exists(run_meta_path): with gfile.GFile(run_meta_path, "rb") as file: run_meta.MergeFromString(file.read()) print("Loaded RunMetadata from {}".format(run_meta_path)) else: print("RunMetadata does not exist a {}. Skipping.".format(run_meta_path)) # Import Graph graph_def_path = os.path.join(model_dir, "graph.pbtxt") graph = tf.Graph() if gfile.Exists(graph_def_path): with graph.as_default(): _register_function_ops(CUSTOM_OP_FUNCTIONS) graph_def = tf.GraphDef() with gfile.GFile(graph_def_path, "rb") as file: text_format.Parse(file.read(), graph_def) tf.import_graph_def(graph_def, name="") print("Loaded Graph from {}".format(graph_def_path)) else: print("Graph does not exist a {}. Skipping.".format(graph_def_path)) # Import OpLog op_log_path = os.path.join(model_dir, "metadata/tfprof_log") op_log = tfprof_log_pb2.OpLog() if gfile.Exists(op_log_path): with gfile.GFile(op_log_path, "rb") as file: op_log.MergeFromString(file.read()) print("Loaded OpLog from {}".format(op_log_path)) else: print("OpLog does not exist a {}. Skipping.".format(op_log_path)) return run_meta, graph, op_log