本文整理汇总了Python中tensorflow.python.platform.gfile.Glob方法的典型用法代码示例。如果您正苦于以下问题:Python gfile.Glob方法的具体用法?Python gfile.Glob怎么用?Python gfile.Glob使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.python.platform.gfile
的用法示例。
在下文中一共展示了gfile.Glob方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_maxiter_weights
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def get_maxiter_weights(dir):
try:
filenames = gfile.Glob(dir + '/model*')
except NotFoundError:
print('nothing found at ', dir + '/model*')
return None
iternums = []
if len(filenames) != 0:
for f in filenames:
try:
iternums.append(int(re.match('.*?([0-9]+)$', f).group(1)))
except:
iternums.append(-1)
iternums = np.array(iternums)
return filenames[np.argmax(iternums)].split('.')[0] # skip the str after the '.'
else:
return None
示例2: convert
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def convert(data_path):
# iterate through the data splits
for data_split in ['train', 'test']:
os.makedirs(os.path.join(data_path, data_split))
data_split_path = os.path.join(data_path, 'softmotion30_44k', data_split)
data_split_files = gfile.Glob(os.path.join(data_split_path, '*'))
# iterate through the TF records
for f in data_split_files:
print('Current file: ' + f)
ind = int(f.split('/')[-1].split('_')[1]) # starting video index
# iterate through the sequences in this TF record
for serialized_example in tf.python_io.tf_record_iterator(f):
os.makedirs(os.path.join(data_path, data_split, str(ind)))
example = tf.train.Example()
example.ParseFromString(serialized_example)
# iterate through the sequence
for i in range(30):
image_name = str(i) + '/image_aux1/encoded'
byte_str = example.features.feature[image_name].bytes_list.value[0]
img = Image.frombytes('RGB', (64, 64), byte_str)
img = np.array(img.getdata()).reshape(img.size[1], img.size[0], 3) / 255.
imsave(os.path.join(data_path, data_split, str(ind), str(i) + '.png'), img)
print(' Finished processing sequence ' + str(ind))
ind += 1
示例3: build_image_input
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def build_image_input(train=True, novel=True):
"""Create input tfrecord tensors.
Args:
novel: whether or not to grab novel or seen images.
Returns:
list of tensors corresponding to images. The images
tensor is 5D, batch x time x height x width x channels.
Raises:
RuntimeError: if no files found.
"""
if train:
data_dir = os.path.expanduser('~/Downloads/google_brainrobotdata_push')
elif novel:
data_dir = os.path.expanduser('~/Downloads/google_brainrobotdata_push')
else:
data_dir = os.path.expanduser('~/Downloads/google_brainrobotdata_push')
filenames = gfile.Glob(os.path.join(data_dir, '*'))
print(filenames)
if not filenames:
raise RuntimeError('No data files found.')
filename_queue = tf.train.string_input_producer(filenames, shuffle=False)
reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
示例4: create_data_list
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def create_data_list(image_dir):
if not gfile.Exists(image_dir):
print("Image director '" + image_dir + "' not found.")
return None
extensions = ['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG']
print("Looking for images in '" + image_dir + "'")
file_list = []
for extension in extensions:
file_glob = os.path.join(image_dir, '*.' + extension)
file_list.extend(gfile.Glob(file_glob))
if not file_list:
print("No files found in '" + image_dir + "'")
return None
images = []
labels = []
for file_name in file_list:
image = Image.open(file_name)
image_gray = image.convert('L')
image_resize = image_gray.resize(size=(IMAGE_WIDTH,IMAGE_HEIGHT))
input_img = np.array(image_resize, dtype='int16')
image.close()
label_name = os.path.basename(file_name).split('_')[0]
images.append(input_img)
labels.append(label_name)
return zip(images, labels)
示例5: prepare_background_data
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def prepare_background_data(self):
"""Searches a folder for background noise audio, and loads it into memory.
It's expected that the background audio samples will be in a subdirectory
named '_background_noise_' inside the 'data_dir' folder, as .wavs that match
the sample rate of the training data, but can be much longer in duration.
If the '_background_noise_' folder doesn't exist at all, this isn't an
error, it's just taken to mean that no background noise augmentation should
be used. If the folder does exist, but it's empty, that's treated as an
error.
Returns:
List of raw PCM-encoded audio samples of background noise.
Raises:
Exception: If files aren't found in the folder.
"""
self.background_data = []
background_dir = os.path.join(self.data_dir, BACKGROUND_NOISE_DIR_NAME)
if not os.path.exists(background_dir):
return self.background_data
with tf.Session(graph=tf.Graph()) as sess:
wav_filename_placeholder = tf.placeholder(tf.string, [])
wav_loader = io_ops.read_file(wav_filename_placeholder)
wav_decoder = contrib_audio.decode_wav(wav_loader, desired_channels=1)
search_path = os.path.join(self.data_dir, BACKGROUND_NOISE_DIR_NAME,
'*.wav')
for wav_path in gfile.Glob(search_path):
wav_data = sess.run(
wav_decoder,
feed_dict={wav_filename_placeholder: wav_path}).audio.flatten()
self.background_data.append(wav_data)
if not self.background_data:
raise Exception('No background wav files were found in ' + search_path)
示例6: get_data_files
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def get_data_files(data_sources):
"""Get data_files from data_sources.
Args:
data_sources: a list/tuple of files or the location of the data, i.e.
/path/to/train@128, /path/to/train* or /tmp/.../train*
Returns:
a list of data_files.
Raises:
ValueError: if not data files are not found
"""
if isinstance(data_sources, (list, tuple)):
data_files = []
for source in data_sources:
data_files += get_data_files(source)
else:
if '*' in data_sources or '?' in data_sources or '[' in data_sources:
data_files = gfile.Glob(data_sources)
else:
data_files = [data_sources]
if not data_files:
raise ValueError('No data files found in %s' % (data_sources,))
return data_files
示例7: _get_file_names
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def _get_file_names(file_pattern, randomize_input):
"""Parse list of file names from pattern, optionally shuffled.
Args:
file_pattern: File glob pattern, or list of glob patterns.
randomize_input: Whether to shuffle the order of file names.
Returns:
List of file names matching `file_pattern`.
Raises:
ValueError: If `file_pattern` is empty, or pattern matches no files.
"""
if isinstance(file_pattern, list):
if not file_pattern:
raise ValueError("File pattern is empty.")
file_names = []
for entry in file_pattern:
file_names.extend(gfile.Glob(entry))
else:
file_names = list(gfile.Glob(file_pattern))
if not file_names:
raise ValueError("No files match %s." % file_pattern)
# Sort files so it will be deterministic for unit tests.
if not randomize_input:
file_names = sorted(file_names)
return file_names
示例8: _expand_file_names
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def _expand_file_names(filepatterns):
"""Takes a list of file patterns and returns a list of resolved file names."""
if not isinstance(filepatterns, (list, tuple, set)):
filepatterns = [filepatterns]
filenames = set()
for filepattern in filepatterns:
names = set(gfile.Glob(filepattern))
filenames |= names
return list(filenames)
示例9: _get_file_names
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def _get_file_names(file_pattern, randomize_input):
"""Parse list of file names from pattern, optionally shuffled.
Args:
file_pattern: File glob pattern, or list of glob patterns.
randomize_input: Whether to shuffle the order of file names.
Returns:
List of file names matching `file_pattern`.
Raises:
ValueError: If `file_pattern` is empty, or pattern matches no files.
"""
if isinstance(file_pattern, list):
if not file_pattern:
raise ValueError('No files given to dequeue_examples.')
file_names = []
for entry in file_pattern:
file_names.extend(gfile.Glob(entry))
else:
file_names = list(gfile.Glob(file_pattern))
if not file_names:
raise ValueError('No files match %s.' % file_pattern)
# Sort files so it will be deterministic for unit tests. They'll be shuffled
# in `string_input_producer` if `randomize_input` is enabled.
if not randomize_input:
file_names = sorted(file_names)
return file_names
示例10: _get_file_names
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def _get_file_names(file_pattern, randomize_input):
"""Parse list of file names from pattern, optionally shuffled.
Args:
file_pattern: File glob pattern, or list of strings.
randomize_input: Whether to shuffle the order of file names.
Returns:
List of file names matching `file_pattern`.
Raises:
ValueError: If `file_pattern` is empty, or pattern matches no files.
"""
if isinstance(file_pattern, list):
file_names = file_pattern
if not file_names:
raise ValueError('No files given to dequeue_examples.')
else:
file_names = list(gfile.Glob(file_pattern))
if not file_names:
raise ValueError('No files match %s.' % file_pattern)
# Sort files so it will be deterministic for unit tests. They'll be shuffled
# in `string_input_producer` if `randomize_input` is enabled.
if not randomize_input:
file_names = sorted(file_names)
return file_names
示例11: test_example1
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def test_example1(self):
n_frames = 5
convert_videos_to_tfrecord(source_path=in_path, destination_path=out_path,
n_videos_in_record=n_videos_per_record,
n_frames_per_video=n_frames,
dense_optical_flow=True,
file_suffix="*.mp4")
filenames = gfile.Glob(os.path.join(out_path, "*.tfrecords"))
n_files = len(filenames)
self.assertTrue(filenames)
self.assertEqual(n_files * n_videos_per_record,
get_number_of_records(filenames, n_frames))
示例12: minibatch
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def minibatch(self, dataset, subset, cache_data=False):
with tf.compat.v1.name_scope('batch_processing'):
glob_pattern = dataset.tf_record_pattern(subset)
file_names = gfile.Glob(glob_pattern)
if not file_names:
raise ValueError('Found no files in --data_dir matching: {}'
.format(glob_pattern))
ds = tf.data.TFRecordDataset.list_files(file_names)
ds = ds.apply(
parallel_interleave(
tf.data.TFRecordDataset, cycle_length=self.num_cores, block_length=5,
sloppy=True,
buffer_output_elements=10000, prefetch_input_elements=10000))
if cache_data:
ds = ds.take(1).cache().repeat()
ds = ds.prefetch(buffer_size=10000)
# num of parallel batches not greater than 56
max_num_parallel_batches = min(56, 2 * self.num_cores)
ds = ds.apply(
map_and_batch(
map_func=self.parse_and_preprocess,
batch_size=self.batch_size,
num_parallel_batches=max_num_parallel_batches,
num_parallel_calls=None))
ds = ds.prefetch(buffer_size=tf.data.experimental.AUTOTUNE) # this number can be tuned
ds_iterator = tf.compat.v1.data.make_one_shot_iterator(ds)
images, labels = ds_iterator.get_next()
# reshape
labels = tf.reshape(labels, [self.batch_size])
return images, labels
示例13: minibatch
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def minibatch(self, dataset, subset, cache_data=False):
with tf.compat.v1.name_scope('batch_processing'):
glob_pattern = dataset.tf_record_pattern(subset)
file_names = gfile.Glob(glob_pattern)
if not file_names:
raise ValueError('Found no files in --data_dir matching: {}'
.format(glob_pattern))
ds = tf.data.TFRecordDataset.list_files(file_names)
ds = ds.apply(
parallel_interleave(
tf.data.TFRecordDataset, cycle_length=self.num_cores, block_length=5,
sloppy=True,
buffer_output_elements=10000, prefetch_input_elements=10000))
if cache_data:
ds = ds.take(1).cache().repeat()
ds = ds.prefetch(buffer_size=10000)
# num of parallel batches not greater than 56
max_num_parallel_batches = min(56, 2*self.num_cores)
ds = ds.apply(
map_and_batch(
map_func=self.parse_and_preprocess,
batch_size=self.batch_size,
num_parallel_batches=max_num_parallel_batches,
num_parallel_calls=None)) # this number should be tuned
ds = ds.prefetch(buffer_size=tf.data.experimental.AUTOTUNE) # this number can be tuned
ds_iterator = tf.compat.v1.data.make_one_shot_iterator(ds)
images, _ = ds_iterator.get_next()
return images
示例14: minibatch
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def minibatch(self, dataset, subset, cache_data=False):
with tf.compat.v1.name_scope('batch_processing'):
glob_pattern = dataset.tf_record_pattern(subset)
file_names = gfile.Glob(glob_pattern)
if not file_names:
raise ValueError('Found no files in --data_dir matching: {}'
.format(glob_pattern))
ds = tf.data.TFRecordDataset.list_files(file_names)
ds = ds.apply(
parallel_interleave(
tf.data.TFRecordDataset, cycle_length=self.num_cores, block_length=5,
sloppy=True,
buffer_output_elements=10000, prefetch_input_elements=10000))
if cache_data:
ds = ds.take(1).cache().repeat()
ds = ds.prefetch(buffer_size=10000)
#ds = ds.prefetch(buffer_size=self.batch_size)
# num of parallel batches not greater than 56
max_num_parallel_batches = min(56, 2 * self.num_cores)
ds = ds.apply(
map_and_batch(
map_func=self.parse_and_preprocess,
batch_size=self.batch_size,
num_parallel_batches=max_num_parallel_batches,
num_parallel_calls=None))
ds = ds.prefetch(buffer_size=tf.data.experimental.AUTOTUNE)
ds_iterator = tf.compat.v1.data.make_one_shot_iterator(ds)
images, labels, filename = ds_iterator.get_next()
# reshape
labels = tf.reshape(labels, [self.batch_size])
filename = tf.reshape(filename, [self.batch_size])
return images, labels, filename
示例15: minibatch
# 需要导入模块: from tensorflow.python.platform import gfile [as 别名]
# 或者: from tensorflow.python.platform.gfile import Glob [as 别名]
def minibatch(self, dataset, subset, cache_data=False):
with tf.compat.v1.name_scope('batch_processing'):
glob_pattern = dataset.tf_record_pattern(subset)
file_names = gfile.Glob(glob_pattern)
if not file_names:
raise ValueError('Found no files in --data_dir matching: {}'
.format(glob_pattern))
ds = tf.data.TFRecordDataset.list_files(file_names)
ds = ds.apply(
parallel_interleave(
tf.data.TFRecordDataset, cycle_length=self.num_cores, block_length=5,
sloppy=True,
buffer_output_elements=10000, prefetch_input_elements=10000))
if cache_data:
ds = ds.take(1).cache().repeat()
ds = ds.prefetch(buffer_size=10000)
# ds = ds.prefetch(buffer_size=self.batch_size)
# num of parallel batches not greater than 56
max_num_parallel_batches = min(56, 2*self.num_cores)
ds = ds.apply(
map_and_batch(
map_func=self.parse_and_preprocess,
batch_size=self.batch_size,
num_parallel_batches=max_num_parallel_batches,
num_parallel_calls=None)) # this number should be tuned
ds = ds.prefetch(buffer_size=tf.data.experimental.AUTOTUNE) # this number can be tuned
ds_iterator = tf.compat.v1.data.make_one_shot_iterator(ds)
images, _ = ds_iterator.get_next()
return images