1+ ### Need some extra paths
2+ import sys ,os
3+ sys .path .append ('modules' )
4+ sys .path .append ('dense_correspondence/dataset' )
5+
6+ ### Set a few environment variables that would've been normally set in Docker
7+ os .environ ["DC_SOURCE_DIR" ]= os .getcwd ()
8+ os .environ ["DC_DATA_DIR" ]= "/home/michelism/Data/pdc"
9+
10+ import dense_correspondence_manipulation .utils .utils as utils
11+ utils .add_dense_correspondence_to_python_path ()
12+ from dense_correspondence .training .training import *
13+ import logging
14+
15+ #utils.set_default_cuda_visible_devices()
16+ #utils.set_cuda_visible_devices([0]) # use this to manually set CUDA_VISIBLE_DEVICES
17+
18+ from dense_correspondence .training .training import DenseCorrespondenceTraining
19+ from dense_correspondence .dataset .spartan_dataset_masked import SpartanDataset
20+ logging .basicConfig (level = logging .INFO )
21+
22+ from dense_correspondence .evaluation .evaluation import DenseCorrespondenceEvaluation
23+
24+
25+ import numpy as np
26+ np .random .seed (42 )# Even this doesn't help... It's absolute chaos random.
27+
28+
29+ config_filename = os .path .join (utils .getDenseCorrespondenceSourceDir (),'config' ,'dense_correspondence' ,
30+ 'dataset' ,'composite' ,'caterpillar_upright.yaml' )
31+ config = utils .getDictFromYamlFilename (config_filename )
32+
33+ train_config_file = os .path .join (utils .getDenseCorrespondenceSourceDir (),'config' ,'dense_correspondence' ,
34+ 'training' ,'training.yaml' )
35+
36+ train_config = utils .getDictFromYamlFilename (train_config_file )
37+ dataset = SpartanDataset (config = config )
38+
39+ logging_dir = "trained_models/tutorials"
40+ num_iterations = 3500
41+ d = 3 # the descriptor dimension
42+ name = "caterpillar_%d" % (d )
43+ train_config ["training" ]["logging_dir_name" ]= name
44+ train_config ["training" ]["logging_dir" ]= logging_dir
45+ train_config ["dense_correspondence_network" ]["descriptor_dimension" ]= d
46+ train_config ["training" ]["num_iterations" ]= num_iterations
47+
48+ TRAIN = True
49+ EVALUATE = True
50+
51+
52+
53+ # All of the saved data for this network will be located in the
54+ # code/data/pdc/trained_models/tutorials/caterpillar_3 folder
55+
56+ if TRAIN :
57+ #print "training descriptor of dimension %d" %(d)
58+ train = DenseCorrespondenceTraining (dataset = dataset ,config = train_config )
59+ train .run ()
60+ #print "finished training descriptor of dimension %d" %(d)
61+
62+
63+ model_folder = os .path .join (logging_dir ,name )
64+ model_folder = utils .convert_data_relative_path_to_absolute_path (model_folder )
65+
66+ if EVALUATE :
67+ DCE = DenseCorrespondenceEvaluation
68+ num_image_pairs = 100
69+ DCE .run_evaluation_on_network (model_folder ,num_image_pairs = num_image_pairs )
70+
71+ from dense_correspondence .evaluation .evaluation import DenseCorrespondenceEvaluationPlotter as DCEP
72+
73+ import matplotlib .pyplot as plt
74+
75+ dc_data_dir = utils .get_data_dir ()
76+
77+ folder_name = "tutorials"
78+ net_to_plot = os .path .join (folder_name ,"caterpillar_3" )
79+
80+ network_name = net_to_plot
81+ path_to_csv = os .path .join (dc_data_dir ,"trained_models" ,network_name ,"analysis/train/data.csv" )
82+ fig_axes = DCEP .run_on_single_dataframe (path_to_csv ,label = network_name ,save = False )
83+
84+ path_to_csv = os .path .join (dc_data_dir ,"trained_models" ,network_name ,"analysis/train/data.csv" )
85+ fig_axes = DCEP .run_on_single_dataframe (path_to_csv ,label = network_name ,previous_fig_axes = fig_axes ,save = False )
86+
87+ plt .savefig ("Training.png" )
88+
89+
90+ path_to_csv = os .path .join (dc_data_dir ,"trained_models" ,network_name ,"analysis/test/data.csv" )
91+ fig_axes = DCEP .run_on_single_dataframe (path_to_csv ,label = network_name ,save = False )
92+
93+ path_to_csv = os .path .join (dc_data_dir ,"trained_models" ,network_name ,"analysis/test/data.csv" )
94+ fig_axes = DCEP .run_on_single_dataframe (path_to_csv ,label = network_name ,previous_fig_axes = fig_axes ,save = False )
95+
96+ plt .savefig ("Test.png" )
97+
98+
99+ path_to_csv = os .path .join (dc_data_dir ,"trained_models" ,network_name ,"analysis/cross_scene/data.csv" )
100+ fig_axes = DCEP .run_on_single_dataframe (path_to_csv ,label = network_name ,save = False )
101+
102+ path_to_csv = os .path .join (dc_data_dir ,"trained_models" ,network_name ,"analysis/cross_scene/data.csv" )
103+ fig_axes = DCEP .run_on_single_dataframe (path_to_csv ,label = network_name ,previous_fig_axes = fig_axes ,save = False )
104+
105+ plt .savefig ("CrossScene.png" )
106+
107+
108+
109+
110+ config_filename = os .path .join (utils .getDenseCorrespondenceSourceDir (),'config' ,
111+ 'dense_correspondence' ,'evaluation' ,'evaluation.yaml' )
112+ config = utils .getDictFromYamlFilename (config_filename )
113+ default_config = utils .get_defaults_config ()
114+
115+ # utils.set_cuda_visible_devices([0])
116+ dce = DenseCorrespondenceEvaluation (config )
117+ DCE = DenseCorrespondenceEvaluation
118+
119+ network_name = "caterpillar_3"
120+ dcn = dce .load_network_from_config (network_name )
121+ dataset = dcn .load_training_dataset ()
122+ DenseCorrespondenceEvaluation .evaluate_network_qualitative (dcn ,dataset = dataset ,randomize = True )