pip
here. Make sure the version number is 2.0: a lot of TensorFlow code online is still in older versions.tf.eager_execution()
. This eager execution now makes TensorFlow an imperative programming environment ("define-by-run") that performs operations straight away, without building pre-constructed graphs with Session.run()
. No longer are computational graphs that run later returned: now operations return actual values letting you write fewer lines of code. It also makes it easier to debug, providing both a better user interface (UI) and more natural control flow with Python statements instead of graph control flow.model = Sequential([ Conv2D(16, 3, padding='same', activation='relu', input_shape=(224, 224, 3)), MaxPooling2D(), Conv2D(32, 3, padding='same', activation='relu'), MaxPooling2D(), Conv2D(64, 3, padding='same', activation='relu'), MaxPooling2D(), Flatten(), Dense(512, activation='relu'), Dense(1, activation='sigmoid') ]) model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy']) history = model.fit_generator( train_data_gen, steps_per_epoch=total_train // batch_size, epochs=epochs, validation_data=val_data_gen, validation_steps=total_val // batch_size )
name
, shape
(dimension), and dtype
(data type). dtype
is common in scientific computing libraries like `NumPy` and `Scikit`.We will see more tensors in #6:import tensorflow as tf x = tf.constant(7.0, dtype=tf.float32) y = tf.constant([1,2,3,4])
x
is a constant integer of type 32-bit single-precision floating-point and y
is a constant array. If you were to print these constants out you'd see that the output is an object of type tensor: Rank | Object |
0 | scalar |
1 | vector |
2 | matrix |
≥ 3 | tensor |
thirdNode = tf.add(5,4) print(thirdNode)
tf.Variable
can be used to store the state of the data for trainable variables like weights and biases:a = tf.Variable(3.14)
name
(ie. "a") and dtype
(ie. "tf.float32") like this:a=tf.Variable(3.14, dtype=tf.float32,name="a")
a
variable.with tf.compat.v1.Session() as sess: print(sess.run(a.initializer)) print(sess.run(a))
import tensorflow as tf import pathlib data_dir = tf.keras.utils.get_file(origin='https://storage.googleapis.com/download.tensorflow.org/example_images/flower_photos.tgz', fname='flower_photos', untar=True) data_dir = pathlib.Path(data_dir)
googleimagesdownload --keywords 'panda' --limit 200 --size medium \
--chromedriver ./chromedriver --format png