本文整理汇总了Python中src.file_utils.fopen方法的典型用法代码示例。如果您正苦于以下问题:Python file_utils.fopen方法的具体用法?Python file_utils.fopen怎么用?Python file_utils.fopen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类src.file_utils
的用法示例。
在下文中一共展示了file_utils.fopen方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_d_at_t
# 需要导入模块: from src import file_utils [as 别名]
# 或者: from src.file_utils import fopen [as 别名]
def save_d_at_t(outputs, global_step, output_dir, metric_summary, N):
"""Save distance to goal at all time steps.
Args:
outputs : [gt_dist_to_goal].
global_step : number of iterations.
output_dir : output directory.
metric_summary : to append scalars to summary.
N : number of outputs to process.
"""
d_at_t = np.concatenate(map(lambda x: x[0][:,:,0]*1, outputs), axis=0)
fig, axes = utils.subplot(plt, (1,1), (5,5))
axes.plot(np.arange(d_at_t.shape[1]), np.mean(d_at_t, axis=0), 'r.')
axes.set_xlabel('time step')
axes.set_ylabel('dist to next goal')
axes.grid('on')
file_name = os.path.join(output_dir, 'dist_at_t_{:d}.png'.format(global_step))
with fu.fopen(file_name, 'w') as f:
fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
file_name = os.path.join(output_dir, 'dist_at_t_{:d}.pkl'.format(global_step))
utils.save_variables(file_name, [d_at_t], ['d_at_t'], overwrite=True)
plt.close(fig)
return None
示例2: _debug_save_map_nodes
# 需要导入模块: from src import file_utils [as 别名]
# 或者: from src.file_utils import fopen [as 别名]
def _debug_save_map_nodes(self, seed):
"""Saves traversible space along with nodes generated on the graph. Takes
the seed as input."""
img_path = os.path.join(self.logdir, '{:s}_{:d}_graph.png'.format(self.building_name, seed))
node_xyt = self.to_actual_xyt_vec(self.task.nodes)
plt.set_cmap('jet');
fig, ax = utils.subplot(plt, (1,1), (12,12))
ax.plot(node_xyt[:,0], node_xyt[:,1], 'm.')
ax.set_axis_off(); ax.axis('equal');
if self.room_dims is not None:
for i, r in enumerate(self.room_dims['dims']*1):
min_ = r[:3]*1
max_ = r[3:]*1
xmin, ymin, zmin = min_
xmax, ymax, zmax = max_
ax.plot([xmin, xmax, xmax, xmin, xmin],
[ymin, ymin, ymax, ymax, ymin], 'g')
ax.imshow(self.traversible, origin='lower');
with fu.fopen(img_path, 'w') as f:
fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
示例3: _vis_readout_maps
# 需要导入模块: from src import file_utils [as 别名]
# 或者: from src.file_utils import fopen [as 别名]
def _vis_readout_maps(outputs, global_step, output_dir, metric_summary, N):
# outputs is [gt_map, pred_map]:
if N >= 0:
outputs = outputs[:N]
N = len(outputs)
plt.set_cmap('jet')
fig, axes = utils.subplot(plt, (N, outputs[0][0].shape[4]*2), (5,5))
axes = axes.ravel()[::-1].tolist()
for i in range(N):
gt_map, pred_map = outputs[i]
for j in [0]:
for k in range(gt_map.shape[4]):
# Display something like the midpoint of the trajectory.
id = np.int(gt_map.shape[1]/2)
ax = axes.pop();
ax.imshow(gt_map[j,id,:,:,k], origin='lower', interpolation='none',
vmin=0., vmax=1.)
ax.set_axis_off();
if i == 0: ax.set_title('gt_map')
ax = axes.pop();
ax.imshow(pred_map[j,id,:,:,k], origin='lower', interpolation='none',
vmin=0., vmax=1.)
ax.set_axis_off();
if i == 0: ax.set_title('pred_map')
file_name = os.path.join(output_dir, 'readout_map_{:d}.png'.format(global_step))
with fu.fopen(file_name, 'w') as f:
fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)
plt.close(fig)
示例4: save_variables
# 需要导入模块: from src import file_utils [as 别名]
# 或者: from src.file_utils import fopen [as 别名]
def save_variables(pickle_file_name, var, info, overwrite = False):
if fu.exists(pickle_file_name) and overwrite == False:
raise Exception('{:s} exists and over write is false.'.format(pickle_file_name))
# Construct the dictionary
assert(type(var) == list); assert(type(info) == list);
d = {}
for i in xrange(len(var)):
d[info[i]] = var[i]
with fu.fopen(pickle_file_name, 'w') as f:
cPickle.dump(d, f, cPickle.HIGHEST_PROTOCOL)
示例5: get_meta_data
# 需要导入模块: from src import file_utils [as 别名]
# 或者: from src.file_utils import fopen [as 别名]
def get_meta_data(self, file_name, data_dir=None):
if data_dir is None:
data_dir = self.get_data_dir()
full_file_name = os.path.join(data_dir, 'meta', file_name)
assert(fu.exists(full_file_name)), \
'{:s} does not exist'.format(full_file_name)
ext = os.path.splitext(full_file_name)[1]
if ext == '.txt':
ls = []
with fu.fopen(full_file_name, 'r') as f:
for l in f:
ls.append(l.rstrip())
elif ext == '.pkl':
ls = utils.load_variables(full_file_name)
return ls
示例6: _debug_save_hardness
# 需要导入模块: from src import file_utils [as 别名]
# 或者: from src.file_utils import fopen [as 别名]
def _debug_save_hardness(self, seed):
out_path = os.path.join(self.logdir, '{:s}_{:d}_hardness.png'.format(self.building_name, seed))
batch_size = 4000
rng = np.random.RandomState(0)
start_node_ids, end_node_ids, dists, pred_maps, paths, hardnesss, gt_dists = \
rng_next_goal_rejection_sampling(
None, batch_size, self.task.gtG, rng, self.task_params.max_dist,
self.task_params.min_dist, self.task_params.max_dist,
self.task.sampling_distribution, self.task.target_distribution,
self.task.nodes, self.task_params.n_ori, self.task_params.step_size,
self.task.distribution_bins, self.task.rejection_sampling_M)
bins = self.task.distribution_bins
n_bins = self.task.n_bins
with plt.style.context('ggplot'):
fig, axes = utils.subplot(plt, (1,2), (10,10))
ax = axes[0]
_ = ax.hist(hardnesss, bins=bins, weights=np.ones_like(hardnesss)/len(hardnesss))
ax.plot(bins[:-1]+0.5/n_bins, self.task.target_distribution, 'g')
ax.plot(bins[:-1]+0.5/n_bins, self.task.sampling_distribution, 'b')
ax.grid('on')
ax = axes[1]
_ = ax.hist(gt_dists, bins=np.arange(self.task_params.max_dist+1))
ax.grid('on')
ax.set_title('Mean: {:0.2f}, Median: {:0.2f}'.format(np.mean(gt_dists),
np.median(gt_dists)))
with fu.fopen(out_path, 'w') as f:
fig.savefig(f, bbox_inches='tight', transparent=True, pad_inches=0)