summaryrefslogtreecommitdiff
path: root/splice.pl
blob: 36bc2d36c9244c3da816e14655a08fbd816e71ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/perl

use Getopt::Long;
use IO::Handle;

STDERR->autoflush(1);
STDOUT->autoflush(1);

my $module = "pix2pixhd";
my $dataset = "PLACEHOLDER";
my $sequence = "PLACEHOLDER";
my $folder_id = 0;
my $start_frame = 0;
my $end_frame = 0;
my $endpoint = undef;
GetOptions (
  "module=s" => \$module,
  "dataset=s"  => \$dataset,
  "sequence=s"  => \$sequence,
  "folder_id=i" => \$folder_id,
  "start_frame=i" => \$start_frame,
  "end_frame=i" => \$end_frame,
  "endpoint=s" => \$endpoint,
)
or die("Error in command line arguments\n");

if ($dataset eq 'PLACEHOLDER' or $sequence eq 'PLACEHOLDER' || ! -e "sequences/$sequence") {
  print "No dataset specified\n";
  exit(1);
}

if ($start_frame == 0 or $end_frame == 0) {
  print "No frames specified\n";
  exit(1);
}

print "module: $module\n";
print "dataset: $dataset\n";
print "sequence: $sequence\n";
print "folder_id: $folder_id\n";
print "start_frame: $start_frame\n";
print "end_frame: $end_frame\n";
print "endpoint: $endpoint\n";

mkdir("./datasets/$dataset");
mkdir("./datasets/$dataset/train_A");
mkdir("./datasets/$dataset/train_B");
mkdir("./datasets/$dataset/test_A");
mkdir("./datasets/$dataset/test_B");
mkdir("./sequences/$dataset");

my $dataset_lines = `ls -1v sequences/$dataset/*.png`;
my @dataset_files = split("\n", $dataset_lines);

my $sequence_lines = `ls -1v sequences/$sequence/*.png`;
my @sequence_files = split('\n', $sequence_lines);

print "Sequence count: " . (scalar @sequence_files) . "\n";
print "Dataset count: " . (scalar @dataset_files) . "\n";

my $pwd = `pwd`;
chomp $pwd;
$pwd .= '/';
print $pwd . "\n";

my $sequence_i = 0;
my $dataset_i = scalar @dataset_files;
my $last_fn = undef;
for my $filename (@sequence_files) {
  if ($start_frame <= $sequence_i and $sequence_i <= $end_frame) {
    chomp $filename;
    print($pwd . $filename. "\n");
    system('ln', '-s', $pwd . $filename, sprintf('./sequences/%s/frame_%05d.png', $dataset, $dataset_i));
    if (defined $last_fn) {
      my $a_fn = sprintf('./datasets/%s/train_A/%s_%05d.png', $dataset, $sequence, $sequence_i);
      my $b_fn = sprintf('./datasets/%s/train_B/%s_%05d.png', $dataset, $sequence, $sequence_i);
      if (! -e $a_fn && ! -e $b_fn) {
        system('ln', '-s', $pwd . $last_fn, $a_fn);
        system('ln', '-s', $pwd . $filename, $b_fn);
      }
    }
    $last_fn = $filename;
    $dataset_i += 1;
  }
  if ($end_frame < $sequence_i) {
    break;
  }
  $sequence_i += 1;
}

if (defined $endpoint) {
  print("post to $endpoint\n");
  my $cmd = [
    "curl",
    "  -X POST",
    "  -F folder_id=$folder_id",
    "  -F module=$module",
    "  -F name=$dataset.mov",
    "  -F url=https://s3.amazonaws.com/i.asdf.us/cortex/lens/data/$folder_id/$dataset.mov",
    "  -F dataset=$dataset",
    "  -F activity=splice",
    "  -F processed=1",
    "  -F datatype=video",
    "  " . $endpoint
  ];
  print(join("\n", @$cmd));

  system("curl",
    "-X", "POST",
    "-F", "folder_id=$folder_id",
    "-F", "module=$module",
    "-F", "name=$dataset.mov",
    "-F", "url=https://s3.amazonaws.com/i.asdf.us/cortex/lens/data/$folder_id/$dataset.mov",
    "-F", "dataset=$dataset",
    "-F", "activity=splice",
    "-F", "generated=false",
    "-F", "processed=true",
    "-F", "datatype=video",
    $endpoint
  );
}

END {
  # chdir($parent_dir);
}