Added README.md
[dyncnn.git] / flatland.cc
index 3a59e88..075e073 100644 (file)
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <sys/time.h>
 
 using namespace std;
 
@@ -82,7 +83,6 @@ int main(int argc, char **argv) {
   const scalar_t world_width = 400;
   const scalar_t world_height = 400;
   const scalar_t scaling = 0.16; // So that 400 * 0.16 = 64
-  const scalar_t shape_size = 80;
 
   const scalar_t dt = 0.1;
   const int nb_iterations_per_steps = 5;
@@ -96,7 +96,8 @@ int main(int argc, char **argv) {
 
   int every_nth = 4;
   int nb_frames = 5;
-  int multi_grasp = 0;
+  int random_grasp = 0;
+  int random_shape_size = 0;
   int nb_shapes = 1;
   char data_dir[1024] = "/tmp/";
   int multi_images = 0;
@@ -134,8 +135,13 @@ int main(int argc, char **argv) {
       i++;
     }
 
-    else if(strcmp(argv[i], "--multi_grasp") == 0) {
-      multi_grasp = 1;
+    else if(strcmp(argv[i], "--random_grasp") == 0) {
+      random_grasp = 1;
+      i++;
+    }
+
+    else if(strcmp(argv[i], "--random_shape_size") == 0) {
+      random_shape_size = 1;
       i++;
     }
 
@@ -186,6 +192,10 @@ int main(int argc, char **argv) {
     abort();
   }
 
+  struct timeval start_time, current_time;
+
+  gettimeofday(&start_time, 0);
+
   for(int n = 0; n < nb_sequences; n++) {
 
     Universe *universe;
@@ -203,7 +213,7 @@ int main(int argc, char **argv) {
 
     scalar_t grab_start_x, grab_start_y;
 
-    if(multi_grasp) {
+    if(random_grasp) {
       grab_start_x = world_width * (0.1 + 0.8 * drand48());
       grab_start_y = world_height * (0.1 + 0.8 * drand48());
     } else {
@@ -212,10 +222,16 @@ int main(int argc, char **argv) {
     }
 
     if((n+1)%100 == 0) {
+      gettimeofday(&current_time, 0);
+      int estimated_remaining_time =
+        ((nb_sequences - n) * (current_time.tv_sec - start_time.tv_sec)) / n;
       cout << "Created "
            << n+1 << "/" << nb_sequences << " sequences in "
            << data_dir
-           << "." << endl;
+           << " (~"
+           << estimated_remaining_time/60 << "min"
+           << estimated_remaining_time%60 << "s remaining)."
+           << endl;
     }
 
     do {
@@ -229,6 +245,14 @@ int main(int argc, char **argv) {
 
         nb_attempts = 0;
 
+        scalar_t shape_size;
+
+        if(random_shape_size) {
+          shape_size = 40 + 80 * drand48();
+        } else {
+          shape_size = 80;
+        }
+
         do {
           scalar_t x[] = { - shape_size * 0.4, + shape_size * 0.4,
                            + shape_size * 0.4, - shape_size * 0.4 };