Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def upload_tfrecord(dataset_type, filepath, version, start_frame):
storage = S3(bucket='waymo-dataset-upload')
# str_lasers_range_image = 'edward/{}-lasers-range-image:{}'.format(dataset_type, version)
# str_lasers_range_image_first = 'edward/{}-lasers-range-image-first:{}'.format(dataset_type, version)
# str_lasers_camera_proj = 'edward/{}-lasers-camera-proj:{}'.format(dataset_type, version)
# str_lasers_camera_proj_first = 'edward/{}-lasers-camera-proj-first:{}'.format(dataset_type, version)
# hub_lasers_range_image = hub.load(name=str_lasers_range_image, storage=storage)
# hub_lasers_camera_proj = hub.load(name=str_lasers_camera_proj, storage = storage)
# hub_lasers_range_image_first = hub.load(name=str_lasers_range_image_first, storage=storage)
# hub_lasers_camera_proj_first = hub.load(name=str_lasers_camera_proj_first, storage=storage)
str_labels_laser = 'edward/{}-labels-laser:{}'.format(dataset_type, version)
hub_labels_laser = hub.load(name=str_labels_laser, storage=storage)
dataset = tf.data.TFRecordDataset(filepath)
for batch in dataset.batch(100):
def get_frame_data(data):
def upload_tfrecord(dataset_type, filepath, version, start_frame):
storage = S3(bucket='waymo-dataset-upload')
label_name = 'edward/{}-labels:{}'.format(dataset_type, version)
image_name = 'edward/{}-camera-images:{}'.format(dataset_type, version)
# print('{} {}'.format(label_name, image_name))
images_arr = hub.load(name=image_name, storage=storage)
labels_arr = hub.load(name=label_name, storage=storage)
frame_count = start_frame
dataset = tf.data.TFRecordDataset(filepath)
# print('Yeah {}'.format(frame_count))
for batch in dataset.batch(16):
# print('Cycle')
t1 = clock()
l = batch.shape[0]
arr = np.zeros(shape=(l, 6, 1280, 1920, 3), dtype='uint8')
lab = np.zeros(shape=(l, 2, 6, 30, 7), dtype='float64')
for i in range(0, l):
# print('Cycle2')
def upload_tfrecord(dataset_type, filepath, version, start_frame):
storage = S3(bucket='waymo-dataset-upload')
str_lasers_range_image = 'edward/{}-lasers-range-image:{}'.format(dataset_type, version)
str_lasers_range_image_first = 'edward/{}-lasers-range-image-first:{}'.format(dataset_type, version)
str_lasers_camera_proj = 'edward/{}-lasers-camera-proj:{}'.format(dataset_type, version)
str_lasers_camera_proj_first = 'edward/{}-lasers-camera-proj-first:{}'.format(dataset_type, version)
hub_lasers_range_image = hub.load(name=str_lasers_range_image, storage=storage)
hub_lasers_camera_proj = hub.load(name=str_lasers_camera_proj, storage = storage)
hub_lasers_range_image_first = hub.load(name=str_lasers_range_image_first, storage=storage)
hub_lasers_camera_proj_first = hub.load(name=str_lasers_camera_proj_first, storage=storage)
dataset = tf.data.TFRecordDataset(filepath)
for batch in dataset.batch(1):
def get_arr_image(range_image_compressed):
data = zlib.decompress(range_image_compressed)
mt = open_dataset.MatrixFloat()
mt.ParseFromString(data)
def upload_all():
path = '/home/edward/waymo/training/'
filenames = os.listdir(path)
filenames.sort()
pool = ProcessPool(16)
data = pool.map(frames_tfrecord, map(lambda f: path + f, filenames))
frames = sum(data, 0)
print('Frames in files: {}, Total: {}'.format(data, frames))
start_frame = []
for i in range(0, frames):
start_frame.append(sum(data[:i],0))
dataset_type = 'training'
version = 'v2'
storage = S3(bucket='waymo-dataset-upload')
labels_arr = hub.array(shape=(frames, 2, 6, 30, 7), chunk_size=(100, 2, 6, 30, 7), storage=storage, name='edward/{}-labels:{}'.format(dataset_type, version), backend='s3', dtype='float64')
images_arr = hub.array(compression='jpeg', shape=(frames, 6, 1280, 1920, 3), storage=storage, name='edward/{}-camera-images:{}'.format(dataset_type, version), backend='s3', dtype='uint8', chunk_size=(1, 6, 1280, 1920, 3))
def upload_record(i):
upload_tfrecord(dataset_type, path + filenames[i], version, start_frame[i])
for i in range(0, 5):
print("Stage {}".format(i))
pool.map(upload_record, range(i, len(filenames), 5))
def S3(bucket=None, public=False, aws_access_key_id=None, aws_secret_access_key=None, parallel=25):
return HubBucket(hub.backend.storage.S3(bucket, public, aws_access_key_id, aws_secret_access_key, parallel), 's3')
return frame_count
path = '/home/edward/waymo/validation/'
filenames = os.listdir(path)
filenames.sort()
pool = ProcessPool(16)
data = pool.map(frames_tfrecord, map(lambda f: path + f, filenames))
frames = sum(data, 0)
print('Frames in files: {}, Total: {}'.format(data, frames))
start_frame = []
for i in range(0, frames):
start_frame.append(sum(data[:i],0))
dataset_type = 'validation'
version = 'v2'
storage = S3(bucket='waymo-dataset-upload')
labels_arr = hub.array(shape=(frames, 2, 6, 30, 7), chunk_size=(100, 2, 6, 30, 7), storage=storage, name='edward/{}-labels:{}'.format(dataset_type, version), backend='s3', dtype='float64')
images_arr = hub.array(compression='jpeg', shape=(frames, 6, 1280, 1920, 3), storage=storage, name='edward/{}-camera-images:{}'.format(dataset_type, version), backend='s3', dtype='uint8', chunk_size=(1, 6, 1280, 1920, 3))
def upload_record(i):
waymo_upload.upload_tfrecord(dataset_type, path + filenames[i], version, start_frame[i])
# os.system('python3 -c "from waymo_upload import upload_the_record; upload_the_record() ", {} {} {} {}'.format(dataset_type, path + filenames[i], version, start_frame[i]))
# for i in range(0, len(filenames), 2):
# upload_record(i)
# print("Finished {}".format(filenames[i]))
print("Second stage")
# for i in range(1, len(filenames), 2):
# upload_record(i)
def __map(self, name):
# S3 object storage
if isinstance(name, str) and name == 's3':
return S3()
# GS object storage
elif isinstance(name, str) and name == 'gs':
return GS()
# FileSystem object Storage
elif isinstance(name, str) and name == 'fs':
return FS()
elif isinstance(name, Storage):
return name
raise Exception('Backend not found {}'.format(name))
def main():
path = '/home/edward/waymo/validation/'
dataset_type = 'validation'
version = 'v2'
filenames = os.listdir(path)
filenames.sort()
pool = ProcessPool(16)
frame_count_arr = pool.map(frames_tfrecord, map(lambda f: path + f, filenames))
frames = sum(frame_count_arr, 0)
str_labels_laser = 'edward/{}-labels-laser:{}'.format(dataset_type, version)
storage = S3(bucket='waymo-dataset-upload')
hub.array(shape=(frames, 30, 7), dtype='float64', storage=storage, chunk_size=(100, 30, 7), name=str_labels_laser)
# str_lasers_range_image = 'edward/{}-lasers-range-image:{}'.format(dataset_type, version)
# str_lasers_range_image_first = 'edward/{}-lasers-range-image-first:{}'.format(dataset_type, version)
# str_lasers_camera_proj = 'edward/{}-lasers-camera-proj:{}'.format(dataset_type, version)
# str_lasers_camera_proj_first = 'edward/{}-lasers-camera-proj-first:{}'.format(dataset_type, version)
# storage = S3(bucket='waymo-dataset-upload')
# hub.array(shape=(frames, 4, 2, 200, 600, 4), dtype='float32', backend='s3', storage=storage, name=str_lasers_range_image, chunk_size=(1, 4, 2, 200, 600, 4))
# hub.array(shape=(frames, 4, 2, 200, 600, 6), dtype='int32', backend='s3', storage=storage, name=str_lasers_camera_proj, chunk_size=(1, 4, 2, 200, 600, 6))
# hub.array(shape=(frames, 2, 64, 2650, 4), dtype='float32', backend='s3', storage=storage, name=str_lasers_range_image_first, chunk_size=(1, 2, 64, 2650, 4))
# hub.array(shape=(frames, 2, 64, 2650, 6), dtype='int32', backend='s3', storage=storage, name=str_lasers_camera_proj_first, chunk_size=(1, 2, 64, 2650, 6))
start_frame_arr = []
for i in range(0, len(filenames)):
start_frame_arr.append(sum(frame_count_arr[:i], 0))