results_file = os.path.join('results', save_str)
model_file = os.path.join('models', save_str + '.tar')
plots_file = os.path.join('plots', save_str)

# relevant variables
num_workers = 4
N0 = 2048
N1 = 1000
N2 = 500
num_classes = len(classes)
init_lr = 0.0001
num_epochs = 3

# DATA
# datasets
real_data = ImagesAll(augmented_path, 'real')
render_data = ImagesAll(render_path, 'render')
test_data = Pascal3dAll(pascal3d_path, 'test')
# setup data loaders
real_loader = DataLoader(real_data,
                         batch_size=4,
                         shuffle=True,
                         num_workers=num_workers,
                         pin_memory=True,
                         collate_fn=my_collate)
render_loader = DataLoader(render_data,
                           batch_size=4,
                           shuffle=True,
                           num_workers=num_workers,
                           pin_memory=True,
                           collate_fn=my_collate)
if args.db_type == 'clean':
	db_path = 'data/flipped_new'
else:
	db_path = 'data/flipped_all'
num_classes = len(classes)
real_path = os.path.join(db_path, 'train')
render_path = 'data/renderforcnn'
test_path = os.path.join(db_path, 'test')

# loss
ce_loss = nn.CrossEntropyLoss().cuda()
gve_loss = geodesic_loss().cuda()

# DATA
# datasets
real_data = ImagesAll(real_path, 'real')
render_data = ImagesAll(render_path, 'render')
test_data = TestImages(test_path)
# setup data loaders
real_loader = DataLoader(real_data, batch_size=args.num_workers, shuffle=True, num_workers=args.num_workers, pin_memory=True, collate_fn=my_collate)
render_loader = DataLoader(render_data, batch_size=args.num_workers, shuffle=True, num_workers=args.num_workers, pin_memory=True, collate_fn=my_collate)
test_loader = DataLoader(test_data, batch_size=32)
print('Real: {0} \t Render: {1} \t Test: {2}'.format(len(real_loader), len(render_loader), len(test_loader)))
max_iterations = min(len(real_loader), len(render_loader))


# my_model
class RegressionModel(nn.Module):
	def __init__(self):
		super().__init__()
		self.num_classes = num_classes
Ejemplo n.º 3
0
model_file = os.path.join('models', args.save_str + '.tar')
plots_file = os.path.join('plots', args.save_str)
log_dir = os.path.join('logs', args.save_str)

# relevant variables
ydata_type = 'axis_angle'
ndim = 3
num_classes = len(classes)

mse_loss = nn.MSELoss().cuda()
gve_loss = geodesic_loss().cuda()
ce_loss = nn.CrossEntropyLoss().cuda()

# DATA
# datasets
real_data = ImagesAll(args.augmented_path, 'real', ydata_type)
render_data = ImagesAll(args.render_path, 'render', ydata_type)
test_data = TestImages(args.pascal3d_path, ydata_type)
# setup data loaders
real_loader = DataLoader(real_data,
                         batch_size=args.num_workers,
                         shuffle=True,
                         num_workers=args.num_workers,
                         pin_memory=True,
                         collate_fn=my_collate)
render_loader = DataLoader(render_data,
                           batch_size=args.num_workers,
                           shuffle=True,
                           num_workers=args.num_workers,
                           pin_memory=True,
                           collate_fn=my_collate)
import numpy as np
from sklearn.cluster import KMeans
import pickle
import progressbar
import sys

# relevant paths
image_path = 'data/renderforcnn'

# relevant variables
num_clusters = int(sys.argv[1])
print('num_clusters: ', num_clusters)
kmeans_file = 'data/kmeans_dictionary_axis_angle_' + str(num_clusters) + '.pkl'

# setup data loader to access the images
train_data = ImagesAll(image_path, 'render')
image_names = np.concatenate(train_data.list_image_names)

# get pose targets from training data
bar = progressbar.ProgressBar()
ydata = []
for i in bar(range(len(image_names))):
    image_name = image_names[i]
    _, _, az, el, ct, _ = parse_name(image_name)
    R = rotation_matrix(az, el, -ct)
    y = get_y(R)
    ydata.append(y)
ydata = np.stack(ydata)
print('\nData size: ', ydata.shape)

# run kmeans
# save things here
save_str = 'category_all_10'
results_file = os.path.join('results', save_str)
model_file = os.path.join('models', save_str + '.tar')
plots_file = os.path.join('plots', save_str)

# relevant variables
num_workers = 8
num_classes = len(classes)
init_lr = 0.0001
num_epochs = 50
N0 = 2048
batch_size = 8

# datasets
train_data = ImagesAll(train_path, 'real')
test_data = TestImages(test_path)
# setup data loaders
train_loader = DataLoader(train_data,
                          batch_size=batch_size,
                          shuffle=True,
                          collate_fn=my_collate,
                          num_workers=num_workers)
test_loader = DataLoader(test_data, batch_size=32)
print('Train: {0} \t Test: {1}'.format(len(train_loader), len(test_loader)))


# MODEL
# my model for pose estimation: feature model + 1layer pose model x 12
class my_model(nn.Module):
    def __init__(self):
Ejemplo n.º 6
0
                p.data.add_(-step_size, d_p)

        return loss


if args.db_type == 'clean':
    db_path = 'data/flipped_new'
else:
    db_path = 'data/flipped_all'
num_classes = len(classes)
train_path = os.path.join(db_path, 'train')
test_path = os.path.join(db_path, 'test')
render_path = 'data/renderforcnn/'

# DATA
real_data = ImagesAll(train_path, 'real', args.ydata_type)
render_data = ImagesAll(render_path, 'render', args.ydata_type)
test_data = TestImages(test_path, args.ydata_type)
real_loader = DataLoader(real_data,
                         batch_size=args.num_workers,
                         shuffle=True,
                         num_workers=args.num_workers,
                         pin_memory=True,
                         collate_fn=my_collate)
render_loader = DataLoader(render_data,
                           batch_size=args.num_workers,
                           shuffle=True,
                           num_workers=args.num_workers,
                           pin_memory=True,
                           collate_fn=my_collate)
test_loader = DataLoader(test_data, batch_size=32)
Ejemplo n.º 7
0
N0, N1, N2 = 2048, 1000, 500
num_classes = len(classes)
num_clusters = kmeans.n_clusters
kmeans_dict = kmeans.cluster_centers_

if args.db_type == 'clean':
    db_path = 'data/flipped_new'
else:
    db_path = 'data/flipped_all'
num_classes = len(classes)
train_path = os.path.join(db_path, 'train')
test_path = os.path.join(db_path, 'test')
render_path = 'data/renderforcnn/'

# DATA
real_data = ImagesAll(train_path, 'real', 'axis_angle')
render_data = ImagesAll(render_path, 'render', 'axis_angle')
test_data = TestImages(test_path, 'axis_angle')
real_loader = DataLoader(real_data,
                         batch_size=args.num_workers,
                         shuffle=True,
                         num_workers=args.num_workers,
                         pin_memory=True,
                         collate_fn=my_collate)
render_loader = DataLoader(render_data,
                           batch_size=args.num_workers,
                           shuffle=True,
                           num_workers=args.num_workers,
                           pin_memory=True,
                           collate_fn=my_collate)
test_loader = DataLoader(test_data, batch_size=32)