utils.py 文件源码

python
阅读 35 收藏 0 点赞 0 评论 0

项目:self-driving 作者: BoltzmannBrain 项目源码 文件源码
def prepTruthData(dataPath, numFrames, normalizeData=False):
  """
  Get and preprocess the ground truth drive speeds data.

  Args:
    dataPath: (str) Path to JSON of ground truths.
    numFrames: (int) Number of timesteps to interpolate the data to.
    normalizeData: (bool) Normalize the data to [0,1].
  Returns:
    (list) Linearly interpolated truth values, one for each timestep.
  """
  with open(dataPath, "rb") as infile:
    driveData = json.load(infile)

  # Prep data: make sure it's in order, and use relative position (b/c seconds
  # values may be incorrect)
  driveData.sort(key = lambda x: x[0])
  times = np.zeros(len(driveData))
  speeds = np.zeros(len(driveData))
  for i, (time, speed) in enumerate(driveData):
    times[i] = time
    speeds[i] = speed
  positions = (times - times.min()) / (times.max() - times.min())

  if normalizeData:
    speeds = normalize(speeds)

  # Linearly interpolate the data to the number of video frames
  return np.interp(np.arange(0.0, 1.0, 1.0/numFrames), positions, speeds)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号