Professional Documents
Culture Documents
Code DD
Code DD
Out[75]: '2.10.1'
In [77]: base_model.summary()
Model: "inception_v3"
____________________________________________________________________________________
______________
Layer (type) Output Shape Param # Connected to
====================================================================================
==============
input_3 (InputLayer) [(None, None, None, 0 []
3)]
'activation_198[0]
[0]',
'activation_199[0]
[0]']
64)
[0]']
Normalization) 192)
[0]']
Normalization) 160)
[0]']
Normalization) 160)
Normalization) 192)
192)
'max_pooling2d_11
[0][0]']
[0]']
384)
====================================================================================
==============
Total params: 21,802,784
Trainable params: 21,768,352
Non-trainable params: 34,432
____________________________________________________________________________________
______________
In [78]: len(base_model.layers)
Out[78]: 311
In [80]: base_model.input
Out[81]: [<KerasTensor: shape=(None, None, None, 768) dtype=float32 (created by layer 'mixe
d3')>,
<KerasTensor: shape=(None, None, None, 768) dtype=float32 (created by layer 'mixe
d5')>]
In [84]: plt.imshow(image)
<class 'PIL.Image.Image'>
RGB
In [86]: print(image.mode )
print(len(image.mode))
RGB
3
In [87]: list(image.getdata())
(3, 3, 29),
(4, 7, 22),
(28, 37, 34),
(19, 27, 29),
(19, 25, 41),
(43, 49, 75),
(93, 104, 122),
(84, 96, 122),
(33, 39, 71),
(16, 19, 52),
(14, 17, 48),
(18, 25, 54),
(99, 108, 139),
(63, 66, 99),
(46, 53, 79),
(72, 77, 117),
(20, 22, 60),
(78, 81, 90),
(184, 173, 169),
(137, 128, 119),
(102, 93, 96),
(182, 176, 160),
(141, 130, 134),
(136, 134, 111),
(49, 57, 78),
(33, 50, 102),
(43, 58, 89),
(36, 46, 73),
(51, 63, 101),
(79, 99, 126),
(45, 69, 97),
(40, 54, 93),
(67, 78, 123),
(64, 82, 120),
(81, 86, 116),
(75, 83, 130),
(75, 88, 140),
(54, 71, 115),
(54, 70, 122),
(46, 60, 109),
(42, 54, 102),
(39, 50, 95),
(31, 39, 76),
(14, 20, 52),
(25, 30, 60),
(15, 19, 46),
(175, 177, 198),
(99, 101, 124),
(15, 18, 51),
(22, 27, 65),
(46, 53, 105),
(42, 47, 103),
(75, 80, 120),
(93, 102, 131),
(122, 131, 170),
(86, 110, 182),
<class 'numpy.ndarray'>
(225, 375, 3)
In [95]: len(activations)
Out[95]: 2
In [96]: deep_dream_model.outputs
Out[96]: [<KerasTensor: shape=(None, None, None, 768) dtype=float32 (created by layer 'mixe
d3')>,
<KerasTensor: shape=(None, None, None, 768) dtype=float32 (created by layer 'mixe
d5')>]
losses = []
In [98]: calculate_loss(image,deep_dream_model)
@tf.function
def deep_dream(network, image, learning_rate):
with tf.GradientTape() as tape:
tape.watch(image)
loss = calculate_loss(image, network)
if epoch % 200 == 0:
plt.figure(figsize=(12,12))
plt.imshow(inverse_transform(image))
plt.show()
print('Epoch {}, loss {}'.format(epoch, loss))
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Cell In[107], line 1
----> 1 run_deep_dream(network=deep_dream_model, image=image, epochs = 8000, learnin
g_rate=0.0001)
File ~\anaconda3\envs\DEEP_LEARNIGNG\lib\site-packages\tensorflow\python\util\traceb
ack_utils.py:153, in filter_traceback.<locals>.error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.__traceback__)
--> 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb
File ~\anaconda3\envs\DEEP_LEARNIGNG\lib\site-packages\keras\utils\traceback_utils.p
y:70, in filter_traceback.<locals>.error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.__traceback__)
68 # To get the full stack trace, call:
69 # `tf.debugging.disable_traceback_filtering()`
---> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb
File ~\anaconda3\envs\DEEP_LEARNIGNG\lib\site-packages\keras\engine\training.py:395
8, in _disallow_inside_tf_function(method_name)
3949 if tf.inside_function():
3950 error_msg = (
3951 "Detected a call to `Model.{method_name}` inside a `tf.function`. "
In [ ]: