Related: Import TensorFlow contrib module is slow in TensorFlow 1.2.1 also: What can cause the TensorFlow import to be so slow?
I am using an ssd and importing TensorFlow. I have 4 ghz 8 core pc with 16 gb ram (Processor AMD FX(tm)-8350 Eight-Core Processor, 4000 Mhz, 4 Core(s), 8 Logical Processor(s)). TensorFlow takes 10-12 seconds to import.
Is there any way to selectively import parts of TensorFlow?
Would a RAM disk help?
Is there any more work being done on stuff like this or: Slow to import tensorflow.contrib with Python 3 because inspect.stack is slow #11829?
Edit: Python 3.6.8 :: Anaconda, Inc. on windoze 8.1. Dos box, cygwin bash are slow at 12 seconds. Vs code bash/power shell is fastest at 8 seconds. Importing in a .py file like: import tensorflow as tf. Not sure what environments are.
Edit 2:
PS D:\ray\dev\ml\ss1> conda info --envs
# conda environments:
#
base * D:\Anaconda3
first D:\Anaconda3\envs\first
d:\Anaconda3
first d:\Anaconda3\envs\first
Edit 3: Using the code below, i get 9-10 seconds in a command prompt:
(tf2) D:\ray\dev\ml\ss1>python timeimport.py
import tensorflow: 1 units, 9.796 seconds. 0.1 units/second.
version: 2.0.0
(tf2) D:\ray\dev\ml\ss1>python timeimport.py
import tensorflow: 1 units, 9.448 seconds. 0.11 units/second.
version: 2.0.0
(tf2) D:\ray\dev\ml\ss1>python timeimport.py
import tensorflow: 1 units, 9.421 seconds. 0.11 units/second.
version: 2.0.0
from __future__ import absolute_import, division, print_function, unicode_literals
from contextlib import contextmanager
from timeit import default_timer as timer
@contextmanager
def timing(description: str,units=1,title="",before="") -> None:
if before!="":
print(before,flush=True)
start = timer()
yield
dt = timer() - start
frequency=0 if units is None else (units/dt)
if units is None:
if title is None: print(f"{description}: {dt} seconds.",flush=True)
else: print(f"{title} {description}: {dt} seconds.",flush=True)
else:
#"{0:.2f}".format(a)
dt=round(dt,3)
frequency=round(frequency,2)
print(f"{title} {description}: {str(units)} units, {dt} seconds. {str(frequency)} units/second.",flush=True)
return dt
with timing("import tensorflow",1):
import tensorflow as tf
print("version:",tf.__version__)
Edit 4: turning of windows degender, i get 8-9 seconds instead of 9-10 seconds.
Edit 5: i found a workaround:
make a notebook with:
import tensorflow as tf
print(tf.__version__)
import tensorflow_datasets as tfds
import code.py
then in your code.py:
print("enter imported code")
import tensorflow as tf
print(tf.__version__)
# !pip install -q tensorflow-datasets
import tensorflow_datasets as tfds
import matplotlib.pyplot as plt
import numpy as np
#tfds.list_builders()
ds = tfds.load('mnist', split='train', shuffle_files=True)
...
so you run the notebook once and it takes 10 seconds. next time it goes like the wind.