paufeldman commited on
Commit
b0e2bed
·
1 Parent(s): 3532c82

forzar bifurcaciones

Browse files
Files changed (11) hide show
  1. 128.pth +3 -0
  2. 32.pth +2 -2
  3. 64.pth +2 -2
  4. 64bueno.pth +3 -0
  5. app.ipynb +62 -0
  6. app.py +25 -21
  7. lmodel-700.pth +3 -0
  8. model-700-moreparams-best.pth +3 -0
  9. output.obj +0 -0
  10. sinsub.obj +184 -30
  11. src/mesh_gen/mesh.py +2 -2
128.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:40d4f621c535f8f1776594be90796143d3d4ed5dc9b15b50518bbae7ce9d8183
3
+ size 6714625
32.pth CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4aee59c935e5203ff354f7a34a9e1ea99a4ee7f43a2bcd028d84335bba312f2f
3
- size 6713611
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6c7c0a29c7c3f405dcd7d49539f6eda289b7950698b1c1fd37caa2b8b17cf91f
3
+ size 5012235
64.pth CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:37f658c9e5db8fc3340a133ef1be94c3b1127d2eb74a6d7f94ab812e989c2dff
3
- size 6713611
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d5de52f94fa1744fa8a6a197c5aec3ddb51be758d94f9b5ba104871a9c63fb95
3
+ size 1758859
64bueno.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37f658c9e5db8fc3340a133ef1be94c3b1127d2eb74a6d7f94ab812e989c2dff
3
+ size 6713611
app.ipynb CHANGED
@@ -34,6 +34,68 @@
34
  "from meshSubplot import plotTree"
35
  ]
36
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  {
38
  "cell_type": "code",
39
  "execution_count": 2,
 
34
  "from meshSubplot import plotTree"
35
  ]
36
  },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": null,
40
+ "metadata": {},
41
+ "outputs": [],
42
+ "source": [
43
+ "def decode_testing(v, max, decoder, mult, min):\n",
44
+ " def decode_node(v, max, decoder, mult, min, nbif):\n",
45
+ "\n",
46
+ " cl = decoder.nodeClassifier(v)\n",
47
+ " _, label = torch.max(cl, 1)\n",
48
+ " label = label.data\n",
49
+ " \n",
50
+ " \n",
51
+ " if label == 1 and createNode.count <= max:\n",
52
+ " #print(\"label 1\")\n",
53
+ " right, radius = decoder.internalDecoder(v)\n",
54
+ " \n",
55
+ " d = createNode(1, radius) \n",
56
+ " \n",
57
+ " d.right = decode_node(right, max, decoder, mult, min, nbif = nbif)\n",
58
+ " return d\n",
59
+ "\n",
60
+ " elif label == 2 and createNode.count <= max:\n",
61
+ " #print(\"label 2\")\n",
62
+ " left, right, radius = decoder.bifurcationDecoder(v)\n",
63
+ " \n",
64
+ " d = createNode(1, radius)\n",
65
+ " \n",
66
+ " d.right = decode_node(right, max, decoder, mult, min, nbif = nbif+1)\n",
67
+ " d.left = decode_node(left, max, decoder, mult, min, nbif = nbif+1)\n",
68
+ " \n",
69
+ " return d\n",
70
+ "\n",
71
+ " elif label == 0 : ##output del classifier\n",
72
+ " #print(\"label 0\")\n",
73
+ " if nbif >= 2:\n",
74
+ " #print(\"mayor que min\")\n",
75
+ " radio = decoder.featureDecoder(v)\n",
76
+ " return createNode(1,radio)\n",
77
+ " \n",
78
+ " else:\n",
79
+ " #print(\"menor que min\")\n",
80
+ " left, right, radius = decoder.bifurcationDecoder(v)\n",
81
+ " d = createNode(1, radius)\n",
82
+ " d.right = decode_node(right, max, decoder, mult, min, nbif = nbif+1)\n",
83
+ " d.left = decode_node(left, max, decoder, mult, min, nbif = nbif+1)\n",
84
+ " return d\n",
85
+ "\n",
86
+ " '''\n",
87
+ " elif label == 0 : ##output del classifier\n",
88
+ " print(\"0\", createNode.count)\n",
89
+ " radio = decoder.featureDecoder(v)\n",
90
+ " return createNode(1,radio) \n",
91
+ " '''\n",
92
+ "\n",
93
+ " createNode.count = 0\n",
94
+ " dec = decode_node (v, max, decoder, mult, min, nbif = 0)\n",
95
+ "\n",
96
+ " return dec"
97
+ ]
98
+ },
99
  {
100
  "cell_type": "code",
101
  "execution_count": 2,
app.py CHANGED
@@ -12,6 +12,8 @@ from torch.utils.data import Dataset, DataLoader
12
  import os
13
  from resamplear import *
14
  import open3d as o3d
 
 
15
 
16
  from vedo import *
17
  def count_fn(f):
@@ -30,7 +32,7 @@ def createNode(data, radius, left = None, right = None):
30
  return Node(data, radius, left, right)
31
 
32
  def decode_testing(v, max, decoder, mult, min):
33
- def decode_node(v, max, decoder, mult, min):
34
 
35
  cl = decoder.nodeClassifier(v)
36
  _, label = torch.max(cl, 1)
@@ -43,7 +45,7 @@ def decode_testing(v, max, decoder, mult, min):
43
 
44
  d = createNode(1, radius)
45
 
46
- d.right = decode_node(right, max, decoder, mult, min)
47
  return d
48
 
49
  elif label == 2 and createNode.count <= max:
@@ -52,23 +54,24 @@ def decode_testing(v, max, decoder, mult, min):
52
 
53
  d = createNode(1, radius)
54
 
55
- d.right = decode_node(right, max, decoder, mult, min)
56
- d.left = decode_node(left, max, decoder, mult, min)
57
 
58
  return d
59
 
60
  elif label == 0 : ##output del classifier
61
  #print("label 0")
62
- if createNode.count>min:
63
  #print("mayor que min")
64
  radio = decoder.featureDecoder(v)
65
  return createNode(1,radio)
66
 
67
  else:
68
  #print("menor que min")
69
- right, radius = decoder.internalDecoder(v)
70
- d = createNode(1, radius)
71
- d.right = decode_node(right, max, decoder, mult, min)
 
72
  return d
73
 
74
  '''
@@ -79,7 +82,7 @@ def decode_testing(v, max, decoder, mult, min):
79
  '''
80
 
81
  createNode.count = 0
82
- dec = decode_node (v, max, decoder, mult, min)
83
 
84
  return dec
85
 
@@ -201,7 +204,7 @@ def predict():
201
 
202
 
203
  z = torch.randn(1, latent_size)
204
- generated_images = decode_testing(z, 100, Grassdecoder, mult, 1)
205
  count = []
206
  numerar_nodos(generated_images, count)
207
  #tr(generated_images)
@@ -236,8 +239,8 @@ def predict():
236
  graph_resampled = G
237
  prepararAristas(graph_resampled)
238
  graphOfCenters = GrafoCentros(graph_resampled)
239
-
240
- if abs(max_radius/min_radius)<10:
241
  try:
242
  graphOfCenters.tile()
243
  mesh = tm.Trimesh( graphOfCenters.getVertices(), graphOfCenters.getCaras() )
@@ -245,13 +248,19 @@ def predict():
245
  m2 = mesh_o3d
246
  o3d.io.write_triangle_mesh("sinsub.obj", m2)
247
  mesh_o3d = mesh_o3d.subdivide_loop(3)
248
-
 
 
 
 
 
249
  v_matrix = np.asarray(mesh_o3d.vertices )
250
  f_matrix = np.asarray(mesh_o3d.triangles )
251
  v_matrix_2 = np.asarray(m2.vertices )
252
  f_matrix_2 = np.asarray(m2.triangles )
253
  success = True
254
-
 
255
  except Exception as e:
256
  print("No se pudo generar")
257
  print(str(e))
@@ -278,11 +287,6 @@ def predict():
278
  x=x, y=y, z=z,
279
  i=f_matrix[:,0], j=f_matrix[:,1], k=f_matrix[:,2],
280
  color='red'))
281
-
282
- m = go.Mesh3d(
283
- x=v_matrix[:,0], y=v_matrix[:,1], z=v_matrix[:,2],
284
- i=f_matrix[:,0], j=f_matrix[:,1], k=f_matrix[:,2],
285
- color='red')
286
 
287
  fig.update_layout(
288
  scene = dict(
@@ -300,7 +304,7 @@ def predict():
300
  color='red'))
301
 
302
 
303
- o3d.io.write_triangle_mesh("output.obj", mesh_o3d)
304
  #o3d.io.write_triangle_mesh("generadas/"+filename.split("_")[0]+".obj", mesh_o3d)
305
  return fig
306
 
@@ -313,7 +317,7 @@ Grassdecoder = Grassdecoder
313
 
314
  Grassdecoder.eval()
315
 
316
- checkpoint = torch.load("64.pth", map_location=torch.device('cpu'))
317
  Grassdecoder.load_state_dict(checkpoint['decoder_state_dict'])
318
 
319
  gr.Interface( predict,
 
12
  import os
13
  from resamplear import *
14
  import open3d as o3d
15
+ import pymeshlab as pm
16
+
17
 
18
  from vedo import *
19
  def count_fn(f):
 
32
  return Node(data, radius, left, right)
33
 
34
  def decode_testing(v, max, decoder, mult, min):
35
+ def decode_node(v, max, decoder, mult, min, nbif):
36
 
37
  cl = decoder.nodeClassifier(v)
38
  _, label = torch.max(cl, 1)
 
45
 
46
  d = createNode(1, radius)
47
 
48
+ d.right = decode_node(right, max, decoder, mult, min, nbif = nbif)
49
  return d
50
 
51
  elif label == 2 and createNode.count <= max:
 
54
 
55
  d = createNode(1, radius)
56
 
57
+ d.right = decode_node(right, max, decoder, mult, min, nbif = nbif+1)
58
+ d.left = decode_node(left, max, decoder, mult, min, nbif = nbif+1)
59
 
60
  return d
61
 
62
  elif label == 0 : ##output del classifier
63
  #print("label 0")
64
+ if nbif >= 2:
65
  #print("mayor que min")
66
  radio = decoder.featureDecoder(v)
67
  return createNode(1,radio)
68
 
69
  else:
70
  #print("menor que min")
71
+ left, right, radius = decoder.bifurcationDecoder(v)
72
+ d = createNode(1, radius)
73
+ d.right = decode_node(right, max, decoder, mult, min, nbif = nbif+1)
74
+ d.left = decode_node(left, max, decoder, mult, min, nbif = nbif+1)
75
  return d
76
 
77
  '''
 
82
  '''
83
 
84
  createNode.count = 0
85
+ dec = decode_node (v, max, decoder, mult, min, nbif = 0)
86
 
87
  return dec
88
 
 
204
 
205
 
206
  z = torch.randn(1, latent_size)
207
+ generated_images = decode_testing(z, 50, Grassdecoder, mult, 1)
208
  count = []
209
  numerar_nodos(generated_images, count)
210
  #tr(generated_images)
 
239
  graph_resampled = G
240
  prepararAristas(graph_resampled)
241
  graphOfCenters = GrafoCentros(graph_resampled)
242
+
243
+ if abs(max_radius/min_radius)<10 :
244
  try:
245
  graphOfCenters.tile()
246
  mesh = tm.Trimesh( graphOfCenters.getVertices(), graphOfCenters.getCaras() )
 
248
  m2 = mesh_o3d
249
  o3d.io.write_triangle_mesh("sinsub.obj", m2)
250
  mesh_o3d = mesh_o3d.subdivide_loop(3)
251
+ o3d.io.write_triangle_mesh("output.obj", mesh_o3d)
252
+ ms = pm.MeshSet()
253
+ ms.load_new_mesh('output.obj')
254
+ ms.compute_selection_by_self_intersections_per_face()
255
+ if ms.current_mesh().selected_face_number() > 0:
256
+ raise Exception("autointerseccion")
257
  v_matrix = np.asarray(mesh_o3d.vertices )
258
  f_matrix = np.asarray(mesh_o3d.triangles )
259
  v_matrix_2 = np.asarray(m2.vertices )
260
  f_matrix_2 = np.asarray(m2.triangles )
261
  success = True
262
+
263
+
264
  except Exception as e:
265
  print("No se pudo generar")
266
  print(str(e))
 
287
  x=x, y=y, z=z,
288
  i=f_matrix[:,0], j=f_matrix[:,1], k=f_matrix[:,2],
289
  color='red'))
 
 
 
 
 
290
 
291
  fig.update_layout(
292
  scene = dict(
 
304
  color='red'))
305
 
306
 
307
+
308
  #o3d.io.write_triangle_mesh("generadas/"+filename.split("_")[0]+".obj", mesh_o3d)
309
  return fig
310
 
 
317
 
318
  Grassdecoder.eval()
319
 
320
+ checkpoint = torch.load("64bueno.pth", map_location=torch.device('cpu'))
321
  Grassdecoder.load_state_dict(checkpoint['decoder_state_dict'])
322
 
323
  gr.Interface( predict,
lmodel-700.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:57ad98302bf4787795e6ecbf0cef881bd19a2d49e08bc9baa75287820d6c251e
3
+ size 6911275
model-700-moreparams-best.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23b23467a6a67e8a1c482599ccc96eb86b00261dc88abc8b92b4a73987f0fa7d
3
+ size 66460149
output.obj CHANGED
The diff for this file is too large to render. See raw diff
 
sinsub.obj CHANGED
@@ -1,32 +1,186 @@
1
  # Created by Open3D
2
  # object name: sinsub
3
- # number of vertices: 12
4
- # number of triangles: 16
5
- v 0.449378 0.00737204 0.0931694
6
- v 0.453679 -0.00822981 0.0918463
7
- v 0.443061 -0.0101272 0.0797087
8
- v 0.43876 0.00547462 0.0810317
9
- v 0.540627 0.0390201 0.0148946
10
- v 0.554566 0.0244183 0.00205357
11
- v 0.538313 0.0243431 -0.0155028
12
- v 0.524375 0.0389449 -0.00266178
13
- v 0.539596 0.11558 0.00564692
14
- v 0.54497 0.11561 -0.000638385
15
- v 0.538685 0.115594 -0.00601316
16
- v 0.53331 0.115563 0.000272139
17
- f 5 1 2
18
- f 6 2 3
19
- f 7 3 4
20
- f 8 4 1
21
- f 9 5 6
22
- f 10 6 7
23
- f 11 7 8
24
- f 12 8 5
25
- f 2 6 5
26
- f 3 7 6
27
- f 4 8 7
28
- f 1 5 8
29
- f 6 10 9
30
- f 7 11 10
31
- f 8 12 11
32
- f 5 9 12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Created by Open3D
2
  # object name: sinsub
3
+ # number of vertices: 64
4
+ # number of triangles: 118
5
+ v 0.268613 0.760725 0.82848
6
+ v 0.266527 0.799368 0.833408
7
+ v 0.272015 0.794773 0.871757
8
+ v 0.2741 0.75613 0.866829
9
+ v 0.157212 0.384145 0.608987
10
+ v 0.131787 0.411342 0.606386
11
+ v 0.112836 0.396347 0.634828
12
+ v 0.138262 0.369149 0.637429
13
+ v 0.0888991 0.364763 0.539338
14
+ v 0.0635323 0.39162 0.536601
15
+ v 0.0441923 0.376162 0.564155
16
+ v 0.0695592 0.349305 0.566893
17
+ v 0.0738844 0.328441 0.516638
18
+ v 0.0450704 0.340613 0.509044
19
+ v 0.0365944 0.339917 0.540088
20
+ v 0.0654084 0.327744 0.547682
21
+ v 0.0469728 0.276943 0.534807
22
+ v 0.0213535 0.286892 0.529592
23
+ v 0.0199183 0.296873 0.555685
24
+ v 0.0455376 0.286923 0.5609
25
+ v 0.255122 0.159788 0.472552
26
+ v 0.246212 0.15538 0.464134
27
+ v 0.250882 0.163399 0.454993
28
+ v 0.259792 0.167807 0.463411
29
+ v 0.398679 0.462088 0.592153
30
+ v 0.406057 0.431868 0.626741
31
+ v 0.361328 0.435101 0.639106
32
+ v 0.35395 0.465321 0.604518
33
+ v 0.353219 0.424604 0.578323
34
+ v 0.356619 0.416765 0.595338
35
+ v 0.337885 0.415273 0.598393
36
+ v 0.334486 0.423112 0.581379
37
+ v 0.372671 0.402955 0.574533
38
+ v 0.377977 0.400995 0.595632
39
+ v 0.36726 0.381984 0.596562
40
+ v 0.361953 0.383944 0.575463
41
+ v 0.391938 0.401021 0.564207
42
+ v 0.399242 0.398978 0.586755
43
+ v 0.394687 0.375637 0.586115
44
+ v 0.387383 0.377681 0.563567
45
+ v 0.407004 0.398281 0.564213
46
+ v 0.424101 0.393295 0.579224
47
+ v 0.420022 0.370549 0.576314
48
+ v 0.402924 0.375535 0.561304
49
+ v 0.408443 0.401108 0.549272
50
+ v 0.429123 0.394606 0.553017
51
+ v 0.422549 0.373613 0.552869
52
+ v 0.401869 0.380115 0.549124
53
+ v 0.414358 0.394185 0.525775
54
+ v 0.43369 0.388039 0.527289
55
+ v 0.427382 0.368925 0.530231
56
+ v 0.408051 0.375071 0.528717
57
+ v 0.408054 0.39331 0.493247
58
+ v 0.429845 0.386514 0.495919
59
+ v 0.42272 0.364886 0.49902
60
+ v 0.400929 0.371681 0.496347
61
+ v 0.393319 0.390458 0.46933
62
+ v 0.416006 0.383716 0.480456
63
+ v 0.407487 0.359113 0.48292
64
+ v 0.3848 0.365855 0.471794
65
+ v 0.497995 0.378615 0.455433
66
+ v 0.500065 0.373771 0.470336
67
+ v 0.498388 0.358756 0.465689
68
+ v 0.496319 0.3636 0.450785
69
+ f 13 17 18
70
+ f 14 18 19
71
+ f 15 19 20
72
+ f 16 20 17
73
+ f 9 13 14
74
+ f 10 14 15
75
+ f 11 15 16
76
+ f 21 12 16
77
+ f 22 16 13
78
+ f 23 13 9
79
+ f 24 9 12
80
+ f 5 9 10
81
+ f 6 10 11
82
+ f 7 11 12
83
+ f 8 12 9
84
+ f 1 5 6
85
+ f 2 6 7
86
+ f 3 7 8
87
+ f 4 8 5
88
+ f 25 1 2
89
+ f 26 2 3
90
+ f 27 3 4
91
+ f 28 4 1
92
+ f 29 25 26
93
+ f 30 26 27
94
+ f 31 27 28
95
+ f 32 28 25
96
+ f 33 29 30
97
+ f 34 30 31
98
+ f 35 31 32
99
+ f 36 32 29
100
+ f 37 33 34
101
+ f 38 34 35
102
+ f 39 35 36
103
+ f 40 36 33
104
+ f 41 37 38
105
+ f 42 38 39
106
+ f 43 39 40
107
+ f 44 40 37
108
+ f 45 41 42
109
+ f 46 42 43
110
+ f 47 43 44
111
+ f 48 44 41
112
+ f 49 45 46
113
+ f 50 46 47
114
+ f 51 47 48
115
+ f 52 48 45
116
+ f 53 49 50
117
+ f 54 50 51
118
+ f 55 51 52
119
+ f 56 52 49
120
+ f 57 53 54
121
+ f 58 54 55
122
+ f 59 55 56
123
+ f 60 56 53
124
+ f 61 57 58
125
+ f 62 58 59
126
+ f 63 59 60
127
+ f 64 60 57
128
+ f 18 14 13
129
+ f 19 15 14
130
+ f 20 16 15
131
+ f 17 13 16
132
+ f 14 10 9
133
+ f 15 11 10
134
+ f 16 12 11
135
+ f 16 22 21
136
+ f 13 23 22
137
+ f 9 24 23
138
+ f 12 21 24
139
+ f 10 6 5
140
+ f 11 7 6
141
+ f 12 8 7
142
+ f 9 5 8
143
+ f 6 2 1
144
+ f 7 3 2
145
+ f 8 4 3
146
+ f 5 1 4
147
+ f 2 26 25
148
+ f 3 27 26
149
+ f 4 28 27
150
+ f 1 25 28
151
+ f 26 30 29
152
+ f 27 31 30
153
+ f 28 32 31
154
+ f 25 29 32
155
+ f 30 34 33
156
+ f 31 35 34
157
+ f 32 36 35
158
+ f 29 33 36
159
+ f 34 38 37
160
+ f 35 39 38
161
+ f 36 40 39
162
+ f 33 37 40
163
+ f 38 42 41
164
+ f 39 43 42
165
+ f 40 44 43
166
+ f 37 41 44
167
+ f 42 46 45
168
+ f 43 47 46
169
+ f 44 48 47
170
+ f 41 45 48
171
+ f 46 50 49
172
+ f 47 51 50
173
+ f 48 52 51
174
+ f 45 49 52
175
+ f 50 54 53
176
+ f 51 55 54
177
+ f 52 56 55
178
+ f 49 53 56
179
+ f 54 58 57
180
+ f 55 59 58
181
+ f 56 60 59
182
+ f 53 57 60
183
+ f 58 62 61
184
+ f 59 63 62
185
+ f 60 64 63
186
+ f 57 61 64
src/mesh_gen/mesh.py CHANGED
@@ -12,8 +12,8 @@ class Cuadrado:
12
  self.posicion = posicion
13
  self.normal = normal
14
  self.upVector = upVector
15
- self.sideVector = self.normal.cross( self.upVector )/4
16
- self.upVector = upVector/4
17
 
18
 
19
  self.vertices = [
 
12
  self.posicion = posicion
13
  self.normal = normal
14
  self.upVector = upVector
15
+ self.sideVector = self.normal.cross( self.upVector )/5
16
+ self.upVector = upVector/5
17
 
18
 
19
  self.vertices = [