1
1
import re
2
- from pathlib import Path
3
2
4
3
import keras
5
4
from keras .src import testing
6
5
from keras .src .utils import model_to_dot
7
6
from keras .src .utils import plot_model
8
7
9
8
10
- def assert_file_exists (path ):
11
- assert Path (path ).is_file (), "File does not exist"
12
-
13
-
14
9
def parse_text_from_html (html ):
15
10
pattern = r"<font[^>]*>(.*?)</font>"
16
11
matches = re .findall (pattern , html )
@@ -61,11 +56,11 @@ def test_plot_sequential_model(self):
61
56
62
57
file_name = "sequential.png"
63
58
plot_model (model , file_name )
64
- assert_file_exists (file_name )
59
+ self . assertFileExists (file_name )
65
60
66
61
file_name = "sequential-show_shapes.png"
67
62
plot_model (model , file_name , show_shapes = True )
68
- assert_file_exists (file_name )
63
+ self . assertFileExists (file_name )
69
64
70
65
file_name = "sequential-show_shapes-show_dtype.png"
71
66
plot_model (
@@ -74,7 +69,7 @@ def test_plot_sequential_model(self):
74
69
show_shapes = True ,
75
70
show_dtype = True ,
76
71
)
77
- assert_file_exists (file_name )
72
+ self . assertFileExists (file_name )
78
73
79
74
file_name = "sequential-show_shapes-show_dtype-show_layer_names.png"
80
75
plot_model (
@@ -84,7 +79,7 @@ def test_plot_sequential_model(self):
84
79
show_dtype = True ,
85
80
show_layer_names = True ,
86
81
)
87
- assert_file_exists (file_name )
82
+ self . assertFileExists (file_name )
88
83
89
84
file_name = "sequential-show_shapes-show_dtype-show_layer_names-show_layer_activations.png" # noqa: E501
90
85
plot_model (
@@ -95,7 +90,7 @@ def test_plot_sequential_model(self):
95
90
show_layer_names = True ,
96
91
show_layer_activations = True ,
97
92
)
98
- assert_file_exists (file_name )
93
+ self . assertFileExists (file_name )
99
94
100
95
file_name = "sequential-show_shapes-show_dtype-show_layer_names-show_layer_activations-show_trainable.png" # noqa: E501
101
96
plot_model (
@@ -107,7 +102,7 @@ def test_plot_sequential_model(self):
107
102
show_layer_activations = True ,
108
103
show_trainable = True ,
109
104
)
110
- assert_file_exists (file_name )
105
+ self . assertFileExists (file_name )
111
106
112
107
file_name = "sequential-show_shapes-show_dtype-show_layer_names-show_layer_activations-show_trainable-LR.png" # noqa: E501
113
108
plot_model (
@@ -120,7 +115,7 @@ def test_plot_sequential_model(self):
120
115
show_trainable = True ,
121
116
rankdir = "LR" ,
122
117
)
123
- assert_file_exists (file_name )
118
+ self . assertFileExists (file_name )
124
119
125
120
file_name = "sequential-show_layer_activations-show_trainable.png"
126
121
plot_model (
@@ -129,7 +124,7 @@ def test_plot_sequential_model(self):
129
124
show_layer_activations = True ,
130
125
show_trainable = True ,
131
126
)
132
- assert_file_exists (file_name )
127
+ self . assertFileExists (file_name )
133
128
134
129
def test_plot_functional_model (self ):
135
130
inputs = keras .Input ((3 ,), name = "input" )
@@ -167,11 +162,11 @@ def test_plot_functional_model(self):
167
162
168
163
file_name = "functional.png"
169
164
plot_model (model , file_name )
170
- assert_file_exists (file_name )
165
+ self . assertFileExists (file_name )
171
166
172
167
file_name = "functional-show_shapes.png"
173
168
plot_model (model , file_name , show_shapes = True )
174
- assert_file_exists (file_name )
169
+ self . assertFileExists (file_name )
175
170
176
171
file_name = "functional-show_shapes-show_dtype.png"
177
172
plot_model (
@@ -180,7 +175,7 @@ def test_plot_functional_model(self):
180
175
show_shapes = True ,
181
176
show_dtype = True ,
182
177
)
183
- assert_file_exists (file_name )
178
+ self . assertFileExists (file_name )
184
179
185
180
file_name = "functional-show_shapes-show_dtype-show_layer_names.png"
186
181
plot_model (
@@ -190,7 +185,7 @@ def test_plot_functional_model(self):
190
185
show_dtype = True ,
191
186
show_layer_names = True ,
192
187
)
193
- assert_file_exists (file_name )
188
+ self . assertFileExists (file_name )
194
189
195
190
file_name = (
196
191
"functional-show_shapes-show_dtype-show_layer_activations.png"
@@ -203,7 +198,7 @@ def test_plot_functional_model(self):
203
198
show_layer_names = True ,
204
199
show_layer_activations = True ,
205
200
)
206
- assert_file_exists (file_name )
201
+ self . assertFileExists (file_name )
207
202
208
203
file_name = "functional-show_shapes-show_dtype-show_layer_activations-show_trainable.png" # noqa: E501
209
204
plot_model (
@@ -215,7 +210,7 @@ def test_plot_functional_model(self):
215
210
show_layer_activations = True ,
216
211
show_trainable = True ,
217
212
)
218
- assert_file_exists (file_name )
213
+ self . assertFileExists (file_name )
219
214
220
215
file_name = "functional-show_shapes-show_dtype-show_layer_names-show_layer_activations-show_trainable-LR.png" # noqa: E501
221
216
plot_model (
@@ -228,7 +223,7 @@ def test_plot_functional_model(self):
228
223
show_trainable = True ,
229
224
rankdir = "LR" ,
230
225
)
231
- assert_file_exists (file_name )
226
+ self . assertFileExists (file_name )
232
227
233
228
file_name = "functional-show_layer_activations-show_trainable.png"
234
229
plot_model (
@@ -237,7 +232,7 @@ def test_plot_functional_model(self):
237
232
show_layer_activations = True ,
238
233
show_trainable = True ,
239
234
)
240
- assert_file_exists (file_name )
235
+ self . assertFileExists (file_name )
241
236
242
237
file_name = (
243
238
"functional-show_shapes-show_layer_activations-show_trainable.png"
@@ -249,7 +244,7 @@ def test_plot_functional_model(self):
249
244
show_layer_activations = True ,
250
245
show_trainable = True ,
251
246
)
252
- assert_file_exists (file_name )
247
+ self . assertFileExists (file_name )
253
248
254
249
def test_plot_subclassed_model (self ):
255
250
class MyModel (keras .Model ):
@@ -266,11 +261,11 @@ def call(self, x):
266
261
267
262
file_name = "subclassed.png"
268
263
plot_model (model , file_name )
269
- assert_file_exists (file_name )
264
+ self . assertFileExists (file_name )
270
265
271
266
file_name = "subclassed-show_shapes.png"
272
267
plot_model (model , file_name , show_shapes = True )
273
- assert_file_exists (file_name )
268
+ self . assertFileExists (file_name )
274
269
275
270
file_name = "subclassed-show_shapes-show_dtype.png"
276
271
plot_model (
@@ -279,7 +274,7 @@ def call(self, x):
279
274
show_shapes = True ,
280
275
show_dtype = True ,
281
276
)
282
- assert_file_exists (file_name )
277
+ self . assertFileExists (file_name )
283
278
284
279
file_name = "subclassed-show_shapes-show_dtype-show_layer_names.png"
285
280
plot_model (
@@ -289,7 +284,7 @@ def call(self, x):
289
284
show_dtype = True ,
290
285
show_layer_names = True ,
291
286
)
292
- assert_file_exists (file_name )
287
+ self . assertFileExists (file_name )
293
288
294
289
file_name = (
295
290
"subclassed-show_shapes-show_dtype-show_layer_activations.png"
@@ -302,7 +297,7 @@ def call(self, x):
302
297
show_layer_names = True ,
303
298
show_layer_activations = True ,
304
299
)
305
- assert_file_exists (file_name )
300
+ self . assertFileExists (file_name )
306
301
307
302
file_name = "subclassed-show_shapes-show_dtype-show_layer_names-show_layer_activations-show_trainable.png" # noqa: E501
308
303
plot_model (
@@ -314,7 +309,7 @@ def call(self, x):
314
309
show_layer_activations = True ,
315
310
show_trainable = True ,
316
311
)
317
- assert_file_exists (file_name )
312
+ self . assertFileExists (file_name )
318
313
319
314
file_name = "subclassed-show_shapes-show_dtype-show_layer_names-show_layer_activations-show_trainable-LR.png" # noqa: E501
320
315
plot_model (
@@ -327,7 +322,7 @@ def call(self, x):
327
322
show_trainable = True ,
328
323
rankdir = "LR" ,
329
324
)
330
- assert_file_exists (file_name )
325
+ self . assertFileExists (file_name )
331
326
332
327
file_name = "subclassed-show_layer_activations-show_trainable.png"
333
328
plot_model (
@@ -336,7 +331,7 @@ def call(self, x):
336
331
show_layer_activations = True ,
337
332
show_trainable = True ,
338
333
)
339
- assert_file_exists (file_name )
334
+ self . assertFileExists (file_name )
340
335
341
336
file_name = (
342
337
"subclassed-show_shapes-show_layer_activations-show_trainable.png"
@@ -348,7 +343,7 @@ def call(self, x):
348
343
show_layer_activations = True ,
349
344
show_trainable = True ,
350
345
)
351
- assert_file_exists (file_name )
346
+ self . assertFileExists (file_name )
352
347
353
348
def test_plot_nested_functional_model (self ):
354
349
inputs = keras .Input ((3 ,), name = "input" )
@@ -387,7 +382,7 @@ def test_plot_nested_functional_model(self):
387
382
388
383
file_name = "nested-functional.png"
389
384
plot_model (model , file_name , expand_nested = True )
390
- assert_file_exists (file_name )
385
+ self . assertFileExists (file_name )
391
386
392
387
file_name = "nested-functional-show_shapes.png"
393
388
plot_model (
@@ -396,7 +391,7 @@ def test_plot_nested_functional_model(self):
396
391
show_shapes = True ,
397
392
expand_nested = True ,
398
393
)
399
- assert_file_exists (file_name )
394
+ self . assertFileExists (file_name )
400
395
401
396
file_name = "nested-functional-show_shapes-show_dtype.png"
402
397
plot_model (
@@ -406,7 +401,7 @@ def test_plot_nested_functional_model(self):
406
401
show_dtype = True ,
407
402
expand_nested = True ,
408
403
)
409
- assert_file_exists (file_name )
404
+ self . assertFileExists (file_name )
410
405
411
406
file_name = (
412
407
"nested-functional-show_shapes-show_dtype-show_layer_names.png"
@@ -419,7 +414,7 @@ def test_plot_nested_functional_model(self):
419
414
show_layer_names = True ,
420
415
expand_nested = True ,
421
416
)
422
- assert_file_exists (file_name )
417
+ self . assertFileExists (file_name )
423
418
424
419
file_name = "nested-functional-show_shapes-show_dtype-show_layer_names-show_layer_activations.png" # noqa: E501
425
420
plot_model (
@@ -431,7 +426,7 @@ def test_plot_nested_functional_model(self):
431
426
show_layer_activations = True ,
432
427
expand_nested = True ,
433
428
)
434
- assert_file_exists (file_name )
429
+ self . assertFileExists (file_name )
435
430
436
431
file_name = "nested-functional-show_shapes-show_dtype-show_layer_names-show_layer_activations-show_trainable.png" # noqa: E501
437
432
plot_model (
@@ -444,7 +439,7 @@ def test_plot_nested_functional_model(self):
444
439
show_trainable = True ,
445
440
expand_nested = True ,
446
441
)
447
- assert_file_exists (file_name )
442
+ self . assertFileExists (file_name )
448
443
449
444
file_name = "nested-functional-show_shapes-show_dtype-show_layer_names-show_layer_activations-show_trainable-LR.png" # noqa: E501
450
445
plot_model (
@@ -458,7 +453,7 @@ def test_plot_nested_functional_model(self):
458
453
rankdir = "LR" ,
459
454
expand_nested = True ,
460
455
)
461
- assert_file_exists (file_name )
456
+ self . assertFileExists (file_name )
462
457
463
458
file_name = (
464
459
"nested-functional-show_layer_activations-show_trainable.png"
@@ -470,7 +465,7 @@ def test_plot_nested_functional_model(self):
470
465
show_trainable = True ,
471
466
expand_nested = True ,
472
467
)
473
- assert_file_exists (file_name )
468
+ self . assertFileExists (file_name )
474
469
475
470
file_name = "nested-functional-show_shapes-show_layer_activations-show_trainable.png" # noqa: E501
476
471
plot_model (
@@ -481,7 +476,7 @@ def test_plot_nested_functional_model(self):
481
476
show_trainable = True ,
482
477
expand_nested = True ,
483
478
)
484
- assert_file_exists (file_name )
479
+ self . assertFileExists (file_name )
485
480
486
481
def test_plot_functional_model_with_splits_and_merges (self ):
487
482
class SplitLayer (keras .Layer ):
@@ -518,7 +513,7 @@ def call(self, xs):
518
513
519
514
file_name = "split-functional.png"
520
515
plot_model (model , file_name , expand_nested = True )
521
- assert_file_exists (file_name )
516
+ self . assertFileExists (file_name )
522
517
523
518
file_name = "split-functional-show_shapes.png"
524
519
plot_model (
@@ -527,7 +522,7 @@ def call(self, xs):
527
522
show_shapes = True ,
528
523
expand_nested = True ,
529
524
)
530
- assert_file_exists (file_name )
525
+ self . assertFileExists (file_name )
531
526
532
527
file_name = "split-functional-show_shapes-show_dtype.png"
533
528
plot_model (
@@ -537,4 +532,4 @@ def call(self, xs):
537
532
show_dtype = True ,
538
533
expand_nested = True ,
539
534
)
540
- assert_file_exists (file_name )
535
+ self . assertFileExists (file_name )
0 commit comments