text
stringlengths
1
93.6k
return image, label
dataset = dataset.map(map_fn)
return dataset
def factory_input_fn(params, is_training):
if params['data_source'] == 'tfr':
return tfr_input_fn(params, is_training)
elif params['data_source'] in ['mnist', 'cifar10', 'cifar100', 'lsun']:
return tfds_input_fn(params, params['data_source'], is_training)
# --------------------------------------------------------------------------
# Parse tf records
# --------------------------------------------------------------------------
def parse_tfrecord(params, record):
if params["tfr_format"] == 'progan':
return parse_tfrecord_progan(params, record)
elif params["tfr_format"] == 'inception':
return parse_tfrecord_inception(
params, record,
width=params['img_size'],
height=params['img_size'],
is_training=False, use_summary=params['use_summary'])
else:
raise NotImplementedError("Unrecognised --tfr_format")
def parse_tfrecord_progan(params, record):
'''
Parse the records saved using the NVIDIA ProGAN dataset_tool.py
Data is stored as CHW uint8 with values ranging 0-255
Size is stored beside image byte strings
Data is stored in files with suffix -rN.tfrecords
N = 0 is the largest size, 128x128 in my personal image build
'''
features = tf.parse_single_example(record, features={
'shape': tf.FixedLenFeature([3], tf.int64),
'data': tf.FixedLenFeature([], tf.string)})
data = tf.decode_raw(features['data'], tf.uint8)
# img = tf.reshape(data, features['shape']) # The way from ProGAN
img = tf.reshape(data, [params['img_ch'], params['img_size'], params['img_size']])
img = tf.transpose(img, [1,2,0]) # CHW => HWC
img = tf.cast(img, tf.float32) / 127.5 - 1
empty_label = tf.constant([params['batch_size'], params['num_labels']], dtype=img.dtype)
return img, empty_label
def parse_tfrecord_inception(params, record, width, height, is_training=True, use_summary=False):
'''
Parse the records saved using the tensorflow official inception data build
ERROR: type should be string, got "\thttps://github.com/tensorflow/models\n"
'''
image_buffer, label, bbox, label_text = parse_example_proto(record)
image = image_preprocessing(image_buffer, bbox, is_training, width, height, use_summary=use_summary)
# [batch, height, width, channels] range(-1.0,1.0)
label_one_hot = tf.one_hot(tf.squeeze(label, axis=-1), params['num_labels'], dtype=image.dtype)
return image, label_one_hot
# <FILESEP>
import numpy as np
import constants
from utils.geometry import perspective_projection
import torch
def get_2d_joints(joints_3d, pred_cam_t, focal_length,dev, batch_size ):
rotation = torch.eye(3, device=dev).unsqueeze(0).expand(batch_size, -1, -1)
camera_center = torch.zeros(batch_size, 2, device=dev)
print('cam)t',pred_cam_t)
print('rotaion',rotation)
pred_keypoints_2d = perspective_projection(joints_3d,
rotation=rotation,
translation=pred_cam_t,
focal_length=focal_length,
camera_center=camera_center)
return pred_keypoints_2d
def get_original(proc_parm, verts, cam, joints):