File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 9
9
import base64
10
10
import os
11
11
import shutil
12
+ import time
12
13
import uuid
13
14
from io import BytesIO
15
+ from pathlib import Path
14
16
15
17
import numpy as np
16
18
import onnxruntime as rt
@@ -35,9 +37,23 @@ def setup_module():
35
37
36
38
37
39
class MyTFModel :
38
-
39
40
mnist = tf .keras .datasets .mnist
40
- (x_train , y_train ), (x_test , y_test ) = mnist .load_data ()
41
+ lock_file = os .path .expanduser ("~/.keras/datasets/mnist.npz.downloading" )
42
+ try :
43
+ time_start = time .time ()
44
+ while os .path .exists (lock_file ):
45
+ time .sleep (10 )
46
+ elapsed = time .time () - time_start
47
+ if elapsed > 60 * 15 :
48
+ raise TimeoutError (
49
+ "Timeout when waiting for MNIST data to finished downloading in another process. "
50
+ "Please check internet connection."
51
+ )
52
+ Path (lock_file ).touch ()
53
+ (x_train , y_train ), (x_test , y_test ) = mnist .load_data ()
54
+ finally :
55
+ os .unlink (lock_file )
56
+
41
57
x_train , x_test = x_train / 255.0 , x_test / 255.0
42
58
43
59
x_train , y_train = x_train [:1000 ], y_train [:1000 ]
You can’t perform that action at this time.
0 commit comments