File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 99import base64
1010import os
1111import shutil
12+ import time
1213import uuid
1314from io import BytesIO
15+ from pathlib import Path
1416
1517import numpy as np
1618import onnxruntime as rt
@@ -35,9 +37,25 @@ def setup_module():
3537
3638
3739class MyTFModel :
38-
3940 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+ os .makedirs (os .path .dirname (lock_file ), exist_ok = True )
53+ Path (lock_file ).touch ()
54+ (x_train , y_train ), (x_test , y_test ) = mnist .load_data ()
55+ finally :
56+ if os .path .exists (lock_file ):
57+ os .unlink (lock_file )
58+
4159 x_train , x_test = x_train / 255.0 , x_test / 255.0
4260
4361 x_train , y_train = x_train [:1000 ], y_train [:1000 ]
You can’t perform that action at this time.
0 commit comments