def getNextBatch(batch_num, batch_size, host, port, datapath, keyname):
  global sock
  if sock is None:
    initialize(host, port)

  sock.send_json({'batch_num': batch_num,
                  'batch_size': batch_size,
                  'path': datapath,
                  'keys': [(keyname, 'images0'), 
                           (keyname, 'images1'),
                           (keyname, 'actions'),
                           (keyname, 'timediff')]})
  images = recv_array(sock)
  futures = recv_array(sock)
  futurediffs = normalize(images.astype('float') - futures.astype('float'))

  images = norml(images)   
  futurediffs = norml(futurediffs)
  actions = recv_array(sock)
  timediff = recv_array(sock)

  batch = {'current': images,
           'future': futurediffs,
           'actions': actions,
           'timediff': timediff[:, np.newaxis]
          }

  return batch
def getNextBatch(batch_num, batch_size, host, port, datapath):
    global sock
    if sock is None:
        initialize(host, port)

    sock.send_json(
        {
            "batch_num": batch_num,
            "batch_size": batch_size,
            "path": datapath,
            "keys": [
                ("randompermpairs2", "images0"),
                ("randompermpairs2", "images1"),
                ("randompermpairs2", "actions"),
                ("randompermpairs2", "timediff"),
            ],
        }
    )
    images = norml(recv_array(sock))
    futures = norml(recv_array(sock))
    actions = recv_array(sock)
    timediff = recv_array(sock)

    batch = {"current": images, "future": futures, "actions": actions, "timediff": timediff[:, np.newaxis]}

    return batch
def getNextBatch(N, rng, batch_size):
  sock.send_json({'batch_num': N, 
                  'batch_size': 128})
  info = sock.recv_json()
  ims = norml(recv_array(sock))
  norms = norml(recv_array(sock))
  objs = recv_array(sock)

  obss = []
  time_diffs = []
  actionss = []
  future_inds = []  
  while (len(obss) < batch_size):
    i = rng.randint(len(ims))
    if i < OBSERVATION_LENGTH - 1:
      continue
    _b = [info[j].get('teleport_random', False) for j in range(i-OBSERVATION_LENGTH+1, i+1)]
    if any(_b):
      continue
    for j in range(i, min(i+1+MAX_NUM_ACTIONS, len(info))):
      if 'teleport_random' in info[j]s and info[j]['teleport_random']:
        break
    if j == i:
      continue

    t = rng.randint(i+1, j+1)

    if (t, t-i) in zip(future_inds, time_diffs):
      continue

    future_inds.append(t)
    time_diffs.append(t - i)
    
    newshape = (IMAGE_SIZE, IMAGE_SIZE, NUM_CHANNELS * OBSERVATION_LENGTH)
    obs = ims[i - OBSERVATION_LENGTH: i].transpose((1, 2, 3, 0)).reshape(newshape)
    obss.append(obs)
    
    action_seq = []
    for _j in range(i, i + MAX_NUM_ACTIONS):
      if _j < len(info):
         action_seq.extend(process_action(info[_j]))
      else:
         action_seq.extend([0] * ATOMIC_ACTION_LENGTH)
    actionss.append(action_seq)
Exemplo n.º 4
0
def getNextBatch(batch_num, batch_size, host, port, datapath):
    global sock
    if sock is None:
        initialize(host, port)

    sock.send_json(
        {
            "batch_num": batch_num,
            "batch_size": batch_size,
            "path": datapath,
            "keys": [("randomperm", "images"), ("randomperm", "normals")],
        }
    )
    images = norml(recv_array(sock))
    normals = norml(recv_array(sock))

    batch = {"images": images, "normals": normals}  # images

    return batch
Exemplo n.º 5
0
def getNextBatch(batch_num, batch_size, host, port, datapath):
  global sock
  if sock is None:
    initialize(host, port)

  sock.send_json({'batch_num': batch_num,
                  'batch_size': batch_size,
                  'path': datapath,
                  'keys': [('randomperm', 'images'), ('randomperm', 'objectcounts')]})
  images = norml(recv_array(sock))
  counts = recv_array(sock)

  objidvec = np.zeros((batch_size, counts.shape[1] + 1)).astype(np.float)
  objidvec[:, 1:] = counts
  noobj = objidvec.sum(1) == 0
  objidvec[noobj, 0] = 1
  objidvec = objidvec / objidvec.sum(1)[:, np.newaxis]

  batch = {'images': images,        #images
           'object_count_distributions': objidvec     #object-id-present vector
          }

  return batch