Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ar-noc/keras-smoke-detection
  • i3perez/keras-smoke-detection
  • hpwren-dev/keras-smoke-detection
3 results
Show changes
Showing
with 53851 additions and 0 deletions
screenshots/toolate.PNG

45.3 KiB

screenshots/usingotherports.PNG

6.79 KiB

Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
%% Cell type:code id: tags:
``` python
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.layers import SeparableConv2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Activation
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Dense
import matplotlib
matplotlib.use("Agg")
# import the necessary packages
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
# from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import sys
import re
from PIL import Image
import tensorflow as tf
# from imutils import paths
# import the necessary packages
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import sys
import re
from PIL import Image
import pandas as pd
import keras
import tempfile
from tensorflow.keras.callbacks import LambdaCallback
physical_devices = tf.config.experimental.list_physical_devices('GPU')
# physical_devices = tf.config.experimental.list_physical_device
tf.config.experimental.set_memory_growth(physical_devices[0], True)
assert tf.config.experimental.get_memory_growth(physical_devices[0])
import keras
from keras import backend as K
# K.tensorflow_backend._get_available_gpus()
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
dataDirectoryTrain = "/userdata/kerasData/preloaded/flowDirectory2/train/"
dataDirectoryValidation = "/userdata/kerasData/preloaded/flowDirectory2/validation/"
dataDirectoryTest = "/userdata/kerasData/preloaded/flowDirectory2/test/"
TRAIN_SPLIT = 0.75
TEST_SPLIT = 0.25
INIT_LR = 1e-2
BATCH_SIZE = 8
NUM_EPOCHS = 50
image_size = 2048,1536
class_mode = "categorical"
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=30,
zoom_range=0.15,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.15,
validation_split=0,
horizontal_flip=True,
fill_mode="nearest")
image_generatorCLASSIC = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=30,
zoom_range=0,
width_shift_range=0,
height_shift_range=0,
shear_range=0,
validation_split=0,
horizontal_flip=True,
fill_mode="nearest")
trainingGeneratorHPWREN = image_generator.flow_from_directory(
dataDirectoryTrain,
target_size=image_size,
seed=42,
batch_size=BATCH_SIZE,
class_mode=class_mode,
subset="training")
validationGeneratorHPWREN = image_generator.flow_from_directory(
dataDirectoryValidation,
target_size=image_size,
batch_size=BATCH_SIZE,
seed=42,
class_mode=class_mode,
subset = "training")
testGeneratorHPWREN = image_generatorCLASSIC.flow_from_directory(
dataDirectoryTest,
target_size=image_size,
batch_size=BATCH_SIZE,
seed=42,
class_mode=class_mode,
subset = "training")
def f1(y_true, y_pred):
def recall(y_true, y_pred):
"""Recall metric.
Only computes a batch-wise average of recall.
Computes the recall, a metric for multi-label classification of
how many relevant items are selected.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def precision(y_true, y_pred):
"""Precision metric.
Only computes a batch-wise average of precision.
Computes the precision, a metric for multi-label classification of
how many selected items are relevant.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
precision = precision(y_true, y_pred)
recall = recall(y_true, y_pred)
return 2*((precision*recall)/(precision+recall+K.epsilon()))
```
%% Output
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 12397120884647711703
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 7450379519501849834
physical_device_desc: "device: XLA_CPU device"
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 9162883243846547682
physical_device_desc: "device: XLA_GPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 23695670656
locality {
bus_id: 2
numa_node: 1
links {
}
}
incarnation: 5784131758698526549
physical_device_desc: "device: 0, name: TITAN RTX, pci bus id: 0000:86:00.0, compute capability: 7.5"
]
Found 648 images belonging to 2 classes.
Found 243 images belonging to 2 classes.
Found 239 images belonging to 2 classes.
%% Cell type:code id: tags:
``` python
class FireDetectionNet:
@staticmethod
def build(width, height, depth):
# initialize the model along with the input shape to be
# "channels last" and the channels dimension itself
model = Sequential()
inputShape = (height, width, depth)
chanDim = -1
model.add(SeparableConv2D(16, (7, 7), padding="same",
input_shape=inputShape))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(SeparableConv2D(32, (3, 3), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(SeparableConv2D(64, (3, 3), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(SeparableConv2D(64, (3, 3), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(128))
model.add(Activation("relu"))
model.add(BatchNormalization())
model.add(Dropout(0.5))
# second set of FC => RELU layers
model.add(Dense(128))
model.add(Activation("relu"))
model.add(BatchNormalization())
model.add(Dropout(0.5))
# softmax classifier
model.add(Dense(2))
model.add(Activation("softmax"))
# return the constructed network architecture
return model
# name = "HPWRENGroundUp_2048_V1_BATCH"
# opt = SGD(lr=INIT_LR, momentum=0.9,
# decay=INIT_LR / NUM_EPOCHS)
# groundUpModel = FireDetectionNet.build(width=2048, height=1536, depth=3)
# groundUpModel.compile(loss="binary_crossentropy", optimizer=opt,
# metrics=["accuracy", tf.keras.metrics.Precision(), tf.keras.metrics.Recall(), f1])
# mc = tf.keras.callbacks.ModelCheckpoint(f'/userdata/kerasData/pyimagesearch/output/experimental/{name}HPWREN.model',
# monitor='val_loss', mode='auto', save_freq='epoch', verbose=1)
# early_stopping_callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=20)
```
%% Cell type:code id: tags:
``` python
testModel = FireDetectionNet.build(1536,2048,3)
testModel.summary()
```
%% Output
Model: "sequential_1"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
separable_conv2d_4 (Separabl (None, 2048, 1536, 16) 211
_________________________________________________________________
activation_7 (Activation) (None, 2048, 1536, 16) 0
_________________________________________________________________
batch_normalization_6 (Batch (None, 2048, 1536, 16) 64
_________________________________________________________________
max_pooling2d_3 (MaxPooling2 (None, 1024, 768, 16) 0
_________________________________________________________________
separable_conv2d_5 (Separabl (None, 1024, 768, 32) 688
_________________________________________________________________
activation_8 (Activation) (None, 1024, 768, 32) 0
_________________________________________________________________
batch_normalization_7 (Batch (None, 1024, 768, 32) 128
_________________________________________________________________
max_pooling2d_4 (MaxPooling2 (None, 512, 384, 32) 0
_________________________________________________________________
separable_conv2d_6 (Separabl (None, 512, 384, 64) 2400
_________________________________________________________________
activation_9 (Activation) (None, 512, 384, 64) 0
_________________________________________________________________
batch_normalization_8 (Batch (None, 512, 384, 64) 256
_________________________________________________________________
separable_conv2d_7 (Separabl (None, 512, 384, 64) 4736
_________________________________________________________________
activation_10 (Activation) (None, 512, 384, 64) 0
_________________________________________________________________
batch_normalization_9 (Batch (None, 512, 384, 64) 256
_________________________________________________________________
max_pooling2d_5 (MaxPooling2 (None, 256, 192, 64) 0
_________________________________________________________________
flatten_1 (Flatten) (None, 3145728) 0
_________________________________________________________________
dense_3 (Dense) (None, 128) 402653312
_________________________________________________________________
activation_11 (Activation) (None, 128) 0
_________________________________________________________________
batch_normalization_10 (Batc (None, 128) 512
_________________________________________________________________
dropout_2 (Dropout) (None, 128) 0
_________________________________________________________________
dense_4 (Dense) (None, 128) 16512
_________________________________________________________________
activation_12 (Activation) (None, 128) 0
_________________________________________________________________
batch_normalization_11 (Batc (None, 128) 512
_________________________________________________________________
dropout_3 (Dropout) (None, 128) 0
_________________________________________________________________
dense_5 (Dense) (None, 2) 258
_________________________________________________________________
activation_13 (Activation) (None, 2) 0
=================================================================
Total params: 402,679,845
Trainable params: 402,678,981
Non-trainable params: 864
_________________________________________________________________
%% Cell type:code id: tags:
``` python
e8Modeladdress = "/userdata/kerasData/pyimagesearch/output/experimental/HPWRENGroundUp_e8_2048_SPLIT1_v1HPWREN.model"
e7Modeladdress = "/userdata/kerasData/pyimagesearch/output/experimental/HPWRENGroundUp_e8_2048_SPLIT1_v2_e7HPWREN.model"
e6Modeladdress = "/userdata/kerasData/pyimagesearch/output/experimental/HPWRENGroundUp_2048_SPLIT1_v3_e6HPWREN.model"
```
%% Cell type:code id: tags:
``` python
# model = FireDetectionNet.build(width=2048, height=1536, depth=3)
# model.load_weights(e8Modeladdress)
attempt = tf.saved_model.load(e8Modeladdress)
```
%% Cell type:code id: tags:
``` python
e8model = tf.keras.models.load_model(e8Modeladdress,custom_objects={"f1":f1})
e7model = tf.keras.models.load_model(e7Modeladdress,custom_objects={"f1":f1})
e6model = tf.keras.models.load_model(e6Modeladdress,custom_objects={"f1":f1})
```
%% Cell type:code id: tags:
``` python
e8model.evaluate(testGeneratorHPWREN)
```
%% Output
30/30 [==============================] - 338s 11s/step - loss: 0.8079 - accuracy: 0.4351 - precision: 0.4351 - recall: 0.4351 - f1: 0.4351
[0.8078833818435669,
0.4351464509963989,
0.4351464509963989,
0.4351464509963989,
0.43511903285980225]
%% Cell type:code id: tags:
``` python
e7model.evaluate(testGeneratorHPWREN)
```
%% Output
30/30 [==============================] - 239s 8s/step - loss: 0.8104 - accuracy: 0.5397 - precision: 0.5397 - recall: 0.5397 - f1: 0.5393
[0.8103770613670349,
0.5397489666938782,
0.5397489666938782,
0.5397489666938782,
0.5392856597900391]
%% Cell type:code id: tags:
``` python
e6model.evaluate(testGeneratorHPWREN)
```
%% Output
30/30 [==============================] - 242s 8s/step - loss: 0.8597 - accuracy: 0.4728 - precision: 0.4728 - recall: 0.4728 - f1: 0.4720
[0.8597329258918762,
0.47280335426330566,
0.47280335426330566,
0.47280335426330566,
0.47202378511428833]
%% Cell type:code id: tags:
``` python
%matplotlib inline
lrs = LRfINDER.lrs[10:-1]
losses = LRfINDER.losses[10:-1]
plt.plot(lrs, losses)
plt.xscale("log")
plt.xlabel("Learning Rate (Log Scale)")
plt.ylabel("Loss")
```
%% Output
Text(0, 0.5, 'Loss')
%% Cell type:code id: tags:
``` python
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=30,
zoom_range=0.15,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.15,
validation_split=0,
horizontal_flip=True,
fill_mode="nearest")
```
%% Cell type:code id: tags:
``` python
testImage = image_generator.flow_from_("/userdata/kerasData/preloaded/flowDirectory2/test/fire/1512676696_+02100.jpg")))
```
%% Cell type:code id: tags:
``` python
testImage.shape
```
%% Output
(1536, 2048, 3)
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
e6model.predict(testImage)
```
%% Output
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-48-d3b35444c1d2> in <module>
----> 1 e6model.predict(testImage)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
86 raise ValueError('{} is not supported in multi-worker mode.'.format(
87 method.__name__))
---> 88 return method(self, *args, **kwargs)
89
90 return tf_decorator.make_decorator(
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
1266 for step in data_handler.steps():
1267 callbacks.on_predict_batch_begin(step)
-> 1268 tmp_batch_outputs = predict_function(iterator)
1269 # Catch OutOfRangeError for Datasets of unknown size.
1270 # This blocks until the batch has finished executing.
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
578 xla_context.Exit()
579 else:
--> 580 result = self._call(*args, **kwds)
581
582 if tracing_count == self._get_tracing_count():
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
625 # This is the first call of __call__, so we have to initialize.
626 initializers = []
--> 627 self._initialize(args, kwds, add_initializers_to=initializers)
628 finally:
629 # At this point we know that the initialization is complete (or less
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in _initialize(self, args, kwds, add_initializers_to)
504 self._concrete_stateful_fn = (
505 self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access
--> 506 *args, **kwds))
507
508 def invalid_creator_scope(*unused_args, **unused_kwds):
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
2444 args, kwargs = None, None
2445 with self._lock:
-> 2446 graph_function, _, _ = self._maybe_define_function(args, kwargs)
2447 return graph_function
2448
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _maybe_define_function(self, args, kwargs)
2775
2776 self._function_cache.missed.add(call_context_key)
-> 2777 graph_function = self._create_graph_function(args, kwargs)
2778 self._function_cache.primary[cache_key] = graph_function
2779 return graph_function, args, kwargs
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
2665 arg_names=arg_names,
2666 override_flat_arg_shapes=override_flat_arg_shapes,
-> 2667 capture_by_value=self._capture_by_value),
2668 self._function_attributes,
2669 # Tell the ConcreteFunction to clean up its graph once it goes out of
/opt/conda/lib/python3.6/site-packages/tensorflow/python/framework/func_graph.py in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes)
979 _, original_func = tf_decorator.unwrap(python_func)
980
--> 981 func_outputs = python_func(*func_args, **func_kwargs)
982
983 # invariant: `func_outputs` contains only Tensors, CompositeTensors,
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in wrapped_fn(*args, **kwds)
439 # __wrapped__ allows AutoGraph to swap in a converted function. We give
440 # the function a weak reference to itself to avoid a reference cycle.
--> 441 return weak_wrapped_fn().__wrapped__(*args, **kwds)
442 weak_wrapped_fn = weakref.ref(wrapped_fn)
443
/opt/conda/lib/python3.6/site-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
966 except Exception as e: # pylint:disable=broad-except
967 if hasattr(e, "ag_error_metadata"):
--> 968 raise e.ag_error_metadata.to_exception(e)
969 else:
970 raise
ValueError: in user code:
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:1147 predict_function *
outputs = self.distribute_strategy.run(
/opt/conda/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:951 run **
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:2290 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:2649 _call_for_each_replica
return fn(*args, **kwargs)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:1122 predict_step **
return self(x, training=False)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py:886 __call__
self.name)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/input_spec.py:180 assert_input_compatibility
str(x.shape.as_list()))
ValueError: Input 0 of layer sequential is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: [32, 2048, 3]
Source diff could not be displayed: it is too large. Options to address this: view the blob.
Source diff could not be displayed: it is too large. Options to address this: view the blob.
# Scrips for classifcation algorythms
The scrips and notebooks within this directory are everything needed to download the images from HJPWREN and design & test the classifcation algorythms
## Explanations
- getFiles.sh: Code used to download the HPWREN archieve to current directory
Just run this shell file at the place you want the directory to be
- imageLoader.ipynb: Used to sort the HPWREN archieve into (training, testing, validation) subdirectories that Keras can read
<br> ![test](scripts/scripts/getPath.PNG) <br />
Set the mypath to the current location of the HPWREN archieve (filtered)
Set savepath to the directory you want the sorted data archieve (with training, validation, and test )
- trainingScript.py: Used to define the model and use it to train on the subdirectories that was previously created
<br> ![test](scripts/scripts/training.PNG)<br />
Assign all the subdirectories
<br>![test](scripts/scripts/training2.PNG)<br />
This is the location where the model will be saved
<br>![test](scripts/scripts/training3.PNG)<br />
This is the location where the training history will be saved
- historyEvaluator.ipynb: Used to see the training loss and other metrics of training done of script
<br>![test](scripts/scripts/results.PNG)<br />
Assign this to where the training history was saved (above)
- testing.ipynb: Used to test new model on training subset
\ No newline at end of file
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.layers import SeparableConv2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Activation
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Dense
import matplotlib
matplotlib.use("Agg")
# import the necessary packages
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
# from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import sys
import re
from PIL import Image
import matplotlib
matplotlib.use("Agg")
# import the necessary packages
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
# from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import sys
import re
from PIL import Image
import tensorflow as tf
from os import listdir
from os.path import isdir, join, isfile
from numpy import asarray
from numpy import save
import itertools
import matplotlib
matplotlib.use("Agg")
# import the necessary packages
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
# from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import sys
import re
from PIL import Image
import pandas as pd
import keras
import tempfile
from tensorflow.keras.callbacks import LambdaCallback
physical_devices = tf.config.experimental.list_physical_devices('GPU')
# physical_devices = tf.config.experimental.list_physical_device
tf.config.experimental.set_memory_growth(physical_devices[0], True)
assert tf.config.experimental.get_memory_growth(physical_devices[0])
import keras
from keras import backend as K
# K.tensorflow_backend._get_available_gpus()
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
from keras import backend as K
def mcor(y_true, y_pred):
#matthews_correlation
y_pred_pos = K.round(K.clip(y_pred, 0, 1))
y_pred_neg = 1 - y_pred_pos
y_pos = K.round(K.clip(y_true, 0, 1))
y_neg = 1 - y_pos
tp = K.sum(y_pos * y_pred_pos)
tn = K.sum(y_neg * y_pred_neg)
fp = K.sum(y_neg * y_pred_pos)
fn = K.sum(y_pos * y_pred_neg)
numerator = (tp * tn - fp * fn)
denominator = K.sqrt((tp + fp) * (tp + fn) * (tn + fp) * (tn + fn))
return numerator / (denominator + K.epsilon())
def precision(y_true, y_pred):
"""Precision metric.
Only computes a batch-wise average of precision.
Computes the precision, a metric for multi-label classification of
how many selected items are relevant.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
def recall(y_true, y_pred):
"""Recall metric.
Only computes a batch-wise average of recall.
Computes the recall, a metric for multi-label classification of
how many relevant items are selected.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def f1(y_true, y_pred):
def recall(y_true, y_pred):
"""Recall metric.
Only computes a batch-wise average of recall.
Computes the recall, a metric for multi-label classification of
how many relevant items are selected.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def precision(y_true, y_pred):
"""Precision metric.
Only computes a batch-wise average of precision.
Computes the precision, a metric for multi-label classification of
how many selected items are relevant.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
precision = precision(y_true, y_pred)
recall = recall(y_true, y_pred)
return 2*((precision*recall)/(precision+recall+K.epsilon()))
TRAIN_SPLIT = 0.75
TEST_SPLIT = 0.25
INIT_LR = 1e-7
BATCH_SIZE = 32
NUM_EPOCHS = 10000
image_size = 200,200
class_mode = "binary"
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=30,
zoom_range=0.15,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.15,
validation_split=0,
horizontal_flip=True,
fill_mode="nearest")
image_generatorCLASSIC = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=30,
zoom_range=0,
width_shift_range=0,
height_shift_range=0,
shear_range=0,
validation_split=0,
horizontal_flip=True,
fill_mode="nearest")
dataDirectoryTrain = "/userdata/kerasData/preloaded/flowDirectory/train/"
dataDirectoryValidation = "/userdata/kerasData/preloaded/flowDirectory/validation/"
dataDirectoryTest = "/userdata/kerasData/preloaded/flowDirectory/test/"
trainingGeneratorHPWREN = image_generator.flow_from_directory(
dataDirectoryTrain,
target_size=image_size,
seed=42,
batch_size=BATCH_SIZE,
class_mode=class_mode,
subset="training")
validationGeneratorHPWREN = image_generator.flow_from_directory(
dataDirectoryValidation,
target_size=image_size,
batch_size=BATCH_SIZE,
seed=42,
class_mode=class_mode,
subset = "training")
testGeneratorHPWREN = image_generatorCLASSIC.flow_from_directory(
dataDirectoryTest,
target_size=image_size,
batch_size=BATCH_SIZE,
seed=42,
class_mode=class_mode,
subset = "training")
class FireDetectionNet:
@staticmethod
def build(width, height, depth):
# initialize the model along with the input shape to be
# "channels last" and the channels dimension itself
model = Sequential()
inputShape = (height, width, depth)
chanDim = -1
model.add(SeparableConv2D(32, (7, 7), padding="same",
input_shape=inputShape))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(SeparableConv2D(64, (5,5), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(SeparableConv2D(64, (3, 3), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(SeparableConv2D(128, (3, 3), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(5,5)))
model.add(Flatten())
model.add(Dense(64))
model.add(Activation("relu"))
model.add(BatchNormalization())
model.add(Dropout(0.5))
# second set of FC => RELU layers
model.add(Dense(128))
model.add(Activation("relu"))
model.add(BatchNormalization())
model.add(Dropout(0.5))
# softmax classifier
model.add(Dense(2))
model.add(Activation("softmax"))
# return the constructed network architecture
return model
name = "HPWRENGroundUp_1024_SPLIT2_v1_e3"
opt = SGD(lr=INIT_LR, momentum=0.9,
decay=INIT_LR / NUM_EPOCHS)
groundUpModel = FireDetectionNet.build(width=200, height=200, depth=3)
groundUpModel.compile(loss="binary_crossentropy", optimizer=opt,
metrics=["accuracy", precision, recall, f1])
mc = tf.keras.callbacks.ModelCheckpoint(f'/userdata/kerasData/pyimagesearch/output/experimental/{name}HPWREN.model', monitor='val_loss', mode='auto', save_freq='epoch', verbose=1)
early_stopping_callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=50)
history = groundUpModel.fit(
trainingGeneratorHPWREN,
validation_data=validationGeneratorHPWREN,
steps_per_epoch=len(trainingGeneratorHPWREN) // BATCH_SIZE,
validation_steps= len(validationGeneratorHPWREN) // BATCH_SIZE,
epochs=NUM_EPOCHS,
callbacks=[mc, early_stopping_callback],
verbose=1
)
history_df = pd.DataFrame(history.history)
hist_csv_file=f"/userdata/kerasData/output/recreate/{name}"
with open(hist_csv_file, mode='w') as f:
history_df.to_csv(f)
wget -r -A .jpg -l2 --no-parent http://hpwren.ucsd.edu/HPWREN-FIgLib/HPWREN-FIgLib-Data/
ls |grep -v ".*-c$"|xargs -I {} rm -rf {}
find $PWD -maxdepth 2|grep ".*html.*"|xargs -I {} rm -rf {}
Source diff could not be displayed: it is too large. Options to address this: view the blob.
scripts/scripts/getPath.PNG

56.2 KiB

scripts/scripts/getPath_2.PNG

42.4 KiB

scripts/scripts/results.PNG

15.5 KiB

scripts/scripts/training.PNG

39.5 KiB

scripts/scripts/training2.PNG

11.1 KiB

scripts/scripts/training3.PNG

20.7 KiB

%% Cell type:code id: tags:
``` python
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import BatchNormalization
from tensorflow.keras.layers import SeparableConv2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Activation
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Dropout
from tensorflow.keras.layers import Dense
import matplotlib
matplotlib.use("Agg")
# import the necessary packages
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import SGD
from tensorflow.keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
# from imutils import paths
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import sys
import re
from PIL import Image
import tensorflow as tf
# from imutils import paths
# import the necessary packages
import matplotlib.pyplot as plt
import numpy as np
import argparse
import cv2
import os
import sys
import re
from PIL import Image
import pandas as pd
import keras
import tempfile
from tensorflow.keras.callbacks import LambdaCallback
physical_devices = tf.config.experimental.list_physical_devices('GPU')
# physical_devices = tf.config.experimental.list_physical_device
tf.config.experimental.set_memory_growth(physical_devices[0], True)
assert tf.config.experimental.get_memory_growth(physical_devices[0])
import keras
from keras import backend as K
# K.tensorflow_backend._get_available_gpus()
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
dataDirectoryTrain = "/userdata/kerasData/preloaded/flowDirectory2/train/"
dataDirectoryValidation = "/userdata/kerasData/preloaded/flowDirectory2/validation/"
dataDirectoryTest = "/userdata/kerasData/preloaded/flowDirectory2/test/"
TRAIN_SPLIT = 0.75
TEST_SPLIT = 0.25
INIT_LR = 1e-2
BATCH_SIZE = 8
NUM_EPOCHS = 50
image_size = 2048,1536
class_mode = "categorical"
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=30,
zoom_range=0.15,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.15,
validation_split=0,
horizontal_flip=True,
fill_mode="nearest")
image_generatorCLASSIC = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=30,
zoom_range=0,
width_shift_range=0,
height_shift_range=0,
shear_range=0,
validation_split=0,
horizontal_flip=True,
fill_mode="nearest")
trainingGeneratorHPWREN = image_generator.flow_from_directory(
dataDirectoryTrain,
target_size=image_size,
seed=42,
batch_size=BATCH_SIZE,
class_mode=class_mode,
subset="training")
validationGeneratorHPWREN = image_generator.flow_from_directory(
dataDirectoryValidation,
target_size=image_size,
batch_size=BATCH_SIZE,
seed=42,
class_mode=class_mode,
subset = "training")
testGeneratorHPWREN = image_generatorCLASSIC.flow_from_directory(
dataDirectoryTest,
target_size=image_size,
batch_size=BATCH_SIZE,
seed=42,
class_mode=class_mode,
subset = "training")
def precision(y_true, y_pred):
"""Precision metric.
Only computes a batch-wise average of precision.
Computes the precision, a metric for multi-label classification of
how many selected items are relevant.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
def recall(y_true, y_pred):
"""Recall metric.
Only computes a batch-wise average of recall.
Computes the recall, a metric for multi-label classification of
how many relevant items are selected.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def f1(y_true, y_pred):
def recall(y_true, y_pred):
"""Recall metric.
Only computes a batch-wise average of recall.
Computes the recall, a metric for multi-label classification of
how many relevant items are selected.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
possible_positives = K.sum(K.round(K.clip(y_true, 0, 1)))
recall = true_positives / (possible_positives + K.epsilon())
return recall
def precision(y_true, y_pred):
"""Precision metric.
Only computes a batch-wise average of precision.
Computes the precision, a metric for multi-label classification of
how many selected items are relevant.
"""
true_positives = K.sum(K.round(K.clip(y_true * y_pred, 0, 1)))
predicted_positives = K.sum(K.round(K.clip(y_pred, 0, 1)))
precision = true_positives / (predicted_positives + K.epsilon())
return precision
precision = precision(y_true, y_pred)
recall = recall(y_true, y_pred)
return 2*((precision*recall)/(precision+recall+K.epsilon()))
```
%% Output
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 319115137438604482
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 11759642501008274543
physical_device_desc: "device: XLA_CPU device"
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 7382767696932267757
physical_device_desc: "device: XLA_GPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 11197360384
locality {
bus_id: 1
links {
}
}
incarnation: 541433991047198862
physical_device_desc: "device: 0, name: Tesla K40c, pci bus id: 0000:05:00.0, compute capability: 3.5"
]
Found 648 images belonging to 2 classes.
Found 243 images belonging to 2 classes.
Found 239 images belonging to 2 classes.
%% Cell type:code id: tags:
``` python
class FireDetectionNet:
@staticmethod
def build(width, height, depth):
# initialize the model along with the input shape to be
# "channels last" and the channels dimension itself
model = Sequential()
inputShape = (height, width, depth)
chanDim = -1
model.add(SeparableConv2D(16, (7, 7), padding="same",
input_shape=inputShape))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(SeparableConv2D(32, (3, 3), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(SeparableConv2D(64, (3, 3), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(SeparableConv2D(64, (3, 3), padding="same"))
model.add(Activation("relu"))
model.add(BatchNormalization(axis=chanDim))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(128))
model.add(Activation("relu"))
model.add(BatchNormalization())
model.add(Dropout(0.5))
# second set of FC => RELU layers
model.add(Dense(128))
model.add(Activation("relu"))
model.add(BatchNormalization())
model.add(Dropout(0.5))
# softmax classifier
model.add(Dense(2))
model.add(Activation("softmax"))
# return the constructed network architecture
return model
# name = "HPWRENGroundUp_2048_V1_BATCH"
# opt = SGD(lr=INIT_LR, momentum=0.9,
# decay=INIT_LR / NUM_EPOCHS)
# groundUpModel = FireDetectionNet.build(width=2048, height=1536, depth=3)
# groundUpModel.compile(loss="binary_crossentropy", optimizer=opt,
# metrics=["accuracy", tf.keras.metrics.Precision(), tf.keras.metrics.Recall(), f1])
# mc = tf.keras.callbacks.ModelCheckpoint(f'/userdata/kerasData/pyimagesearch/output/experimental/{name}HPWREN.model',
# monitor='val_loss', mode='auto', save_freq='epoch', verbose=1)
# early_stopping_callback = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=20)
```
%% Cell type:code id: tags:
``` python
e8Modeladdress = "/userdata/kerasData/pyimagesearch/output/experimental/HPWRENGroundUp_2048_SPLIT1_v3_e6HPWREN.model"
e7Modeladdress = "/userdata/kerasData/pyimagesearch/output/experimental/HPWRENGroundUp_2048_SPLIT1_v3_e6HPWREN.model"
```
%% Cell type:code id: tags:
``` python
testModel = FireDetectionNet.build(1536,2048,3)
testModel.summary()
```
%% Cell type:code id: tags:
``` python
# model = FireDetectionNet.build(width=2048, height=1536, depth=3)
# model.load_weights(e8Modeladdress)
attempt = tf.saved_model.load(e8Modeladdress)
```
%% Cell type:code id: tags:
``` python
e8model = tf.keras.models.load_model(e8Modeladdress,custom_objects={"f1":f1, "precision":precision, "recall":recall})
e7model = tf.keras.models.load_model(e7Modeladdress,custom_objects={"f1":f1, "precision":precision, "recall":recall})
```
%% Cell type:code id: tags:
``` python
e7model.
e7model.summary()
```
%% Output
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
separable_conv2d (SeparableC (None, 1536, 2048, 16) 211
_________________________________________________________________
activation (Activation) (None, 1536, 2048, 16) 0
_________________________________________________________________
batch_normalization (BatchNo (None, 1536, 2048, 16) 64
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 768, 1024, 16) 0
_________________________________________________________________
separable_conv2d_1 (Separabl (None, 768, 1024, 32) 944
_________________________________________________________________
activation_1 (Activation) (None, 768, 1024, 32) 0
_________________________________________________________________
batch_normalization_1 (Batch (None, 768, 1024, 32) 128
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 384, 512, 32) 0
_________________________________________________________________
separable_conv2d_2 (Separabl (None, 384, 512, 64) 2400
_________________________________________________________________
activation_2 (Activation) (None, 384, 512, 64) 0
_________________________________________________________________
batch_normalization_2 (Batch (None, 384, 512, 64) 256
_________________________________________________________________
separable_conv2d_3 (Separabl (None, 384, 512, 64) 4736
_________________________________________________________________
activation_3 (Activation) (None, 384, 512, 64) 0
_________________________________________________________________
batch_normalization_3 (Batch (None, 384, 512, 64) 256
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 76, 102, 64) 0
_________________________________________________________________
flatten (Flatten) (None, 496128) 0
_________________________________________________________________
dense (Dense) (None, 64) 31752256
_________________________________________________________________
activation_4 (Activation) (None, 64) 0
_________________________________________________________________
batch_normalization_4 (Batch (None, 64) 256
_________________________________________________________________
dropout (Dropout) (None, 64) 0
_________________________________________________________________
dense_1 (Dense) (None, 128) 8320
_________________________________________________________________
activation_5 (Activation) (None, 128) 0
_________________________________________________________________
batch_normalization_5 (Batch (None, 128) 512
_________________________________________________________________
dropout_1 (Dropout) (None, 128) 0
_________________________________________________________________
dense_2 (Dense) (None, 2) 258
_________________________________________________________________
activation_6 (Activation) (None, 2) 0
=================================================================
Total params: 31,770,597
Trainable params: 31,769,861
Non-trainable params: 736
_________________________________________________________________
%% Cell type:code id: tags:
``` python
e8model.summary()
```
%% Output
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
separable_conv2d (SeparableC (None, 1536, 2048, 16) 211
_________________________________________________________________
activation (Activation) (None, 1536, 2048, 16) 0
_________________________________________________________________
batch_normalization (BatchNo (None, 1536, 2048, 16) 64
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 768, 1024, 16) 0
_________________________________________________________________
separable_conv2d_1 (Separabl (None, 768, 1024, 32) 944
_________________________________________________________________
activation_1 (Activation) (None, 768, 1024, 32) 0
_________________________________________________________________
batch_normalization_1 (Batch (None, 768, 1024, 32) 128
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 384, 512, 32) 0
_________________________________________________________________
separable_conv2d_2 (Separabl (None, 384, 512, 64) 2400
_________________________________________________________________
activation_2 (Activation) (None, 384, 512, 64) 0
_________________________________________________________________
batch_normalization_2 (Batch (None, 384, 512, 64) 256
_________________________________________________________________
separable_conv2d_3 (Separabl (None, 384, 512, 64) 4736
_________________________________________________________________
activation_3 (Activation) (None, 384, 512, 64) 0
_________________________________________________________________
batch_normalization_3 (Batch (None, 384, 512, 64) 256
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 76, 102, 64) 0
_________________________________________________________________
flatten (Flatten) (None, 496128) 0
_________________________________________________________________
dense (Dense) (None, 64) 31752256
_________________________________________________________________
activation_4 (Activation) (None, 64) 0
_________________________________________________________________
batch_normalization_4 (Batch (None, 64) 256
_________________________________________________________________
dropout (Dropout) (None, 64) 0
_________________________________________________________________
dense_1 (Dense) (None, 128) 8320
_________________________________________________________________
activation_5 (Activation) (None, 128) 0
_________________________________________________________________
batch_normalization_5 (Batch (None, 128) 512
_________________________________________________________________
dropout_1 (Dropout) (None, 128) 0
_________________________________________________________________
dense_2 (Dense) (None, 2) 258
_________________________________________________________________
activation_6 (Activation) (None, 2) 0
=================================================================
Total params: 31,770,597
Trainable params: 31,769,861
Non-trainable params: 736
_________________________________________________________________
%% Cell type:code id: tags:
``` python
e1048model = tf.keras.models.load_model("/userdata/kerasData/pyimagesearch/output/experimental/HPWRENGroundUp_1024_SPLIT1_v1_e3HPWREN.model",custom_objects={"f1":f1, "precision":precision, "recall":recall})
e1048model.summary()
```
%% Output
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
separable_conv2d (SeparableC (None, 768, 1024, 32) 275
_________________________________________________________________
activation (Activation) (None, 768, 1024, 32) 0
_________________________________________________________________
batch_normalization (BatchNo (None, 768, 1024, 32) 128
_________________________________________________________________
max_pooling2d (MaxPooling2D) (None, 384, 512, 32) 0
_________________________________________________________________
separable_conv2d_1 (Separabl (None, 384, 512, 64) 2912
_________________________________________________________________
activation_1 (Activation) (None, 384, 512, 64) 0
_________________________________________________________________
batch_normalization_1 (Batch (None, 384, 512, 64) 256
_________________________________________________________________
max_pooling2d_1 (MaxPooling2 (None, 192, 256, 64) 0
_________________________________________________________________
separable_conv2d_2 (Separabl (None, 192, 256, 64) 4736
_________________________________________________________________
activation_2 (Activation) (None, 192, 256, 64) 0
_________________________________________________________________
batch_normalization_2 (Batch (None, 192, 256, 64) 256
_________________________________________________________________
separable_conv2d_3 (Separabl (None, 192, 256, 128) 8896
_________________________________________________________________
activation_3 (Activation) (None, 192, 256, 128) 0
_________________________________________________________________
batch_normalization_3 (Batch (None, 192, 256, 128) 512
_________________________________________________________________
separable_conv2d_4 (Separabl (None, 192, 256, 256) 34176
_________________________________________________________________
activation_4 (Activation) (None, 192, 256, 256) 0
_________________________________________________________________
batch_normalization_4 (Batch (None, 192, 256, 256) 1024
_________________________________________________________________
max_pooling2d_2 (MaxPooling2 (None, 38, 51, 256) 0
_________________________________________________________________
flatten (Flatten) (None, 496128) 0
_________________________________________________________________
dense (Dense) (None, 64) 31752256
_________________________________________________________________
activation_5 (Activation) (None, 64) 0
_________________________________________________________________
batch_normalization_5 (Batch (None, 64) 256
_________________________________________________________________
dropout (Dropout) (None, 64) 0
_________________________________________________________________
dense_1 (Dense) (None, 128) 8320
_________________________________________________________________
activation_6 (Activation) (None, 128) 0
_________________________________________________________________
batch_normalization_6 (Batch (None, 128) 512
_________________________________________________________________
dropout_1 (Dropout) (None, 128) 0
_________________________________________________________________
dense_2 (Dense) (None, 2) 258
_________________________________________________________________
activation_7 (Activation) (None, 2) 0
=================================================================
Total params: 31,814,773
Trainable params: 31,813,301
Non-trainable params: 1,472
_________________________________________________________________
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
e8model.evaluate(testGeneratorHPWREN)
```
%% Cell type:code id: tags:
``` python
e7model.evaluate(testGeneratorHPWREN)
```
%% Cell type:code id: tags:
``` python
e6model.evaluate(testGeneratorHPWREN)
```
%% Output
30/30 [==============================] - 242s 8s/step - loss: 0.8597 - accuracy: 0.4728 - precision: 0.4728 - recall: 0.4728 - f1: 0.4720
[0.8597329258918762,
0.47280335426330566,
0.47280335426330566,
0.47280335426330566,
0.47202378511428833]
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
%matplotlib inline
lrs = LRfINDER.lrs[10:-1]
losses = LRfINDER.losses[10:-1]
plt.plot(lrs, losses)
plt.xscale("log")
plt.xlabel("Learning Rate (Log Scale)")
plt.ylabel("Loss")
```
%% Output
Text(0, 0.5, 'Loss')
%% Cell type:code id: tags:
``` python
image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rotation_range=30,
zoom_range=0.15,
width_shift_range=0.2,
height_shift_range=0.2,
shear_range=0.15,
validation_split=0,
horizontal_flip=True,
fill_mode="nearest")
```
%% Cell type:code id: tags:
``` python
testImage = image_generator.flow_from_("/userdata/kerasData/preloaded/flowDirectory2/test/fire/1512676696_+02100.jpg")))
```
%% Cell type:code id: tags:
``` python
testImage.shape
```
%% Output
(1536, 2048, 3)
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
e6model.predict(testImage)
```
%% Output
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-48-d3b35444c1d2> in <module>
----> 1 e6model.predict(testImage)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
86 raise ValueError('{} is not supported in multi-worker mode.'.format(
87 method.__name__))
---> 88 return method(self, *args, **kwargs)
89
90 return tf_decorator.make_decorator(
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
1266 for step in data_handler.steps():
1267 callbacks.on_predict_batch_begin(step)
-> 1268 tmp_batch_outputs = predict_function(iterator)
1269 # Catch OutOfRangeError for Datasets of unknown size.
1270 # This blocks until the batch has finished executing.
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in __call__(self, *args, **kwds)
578 xla_context.Exit()
579 else:
--> 580 result = self._call(*args, **kwds)
581
582 if tracing_count == self._get_tracing_count():
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in _call(self, *args, **kwds)
625 # This is the first call of __call__, so we have to initialize.
626 initializers = []
--> 627 self._initialize(args, kwds, add_initializers_to=initializers)
628 finally:
629 # At this point we know that the initialization is complete (or less
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in _initialize(self, args, kwds, add_initializers_to)
504 self._concrete_stateful_fn = (
505 self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access
--> 506 *args, **kwds))
507
508 def invalid_creator_scope(*unused_args, **unused_kwds):
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _get_concrete_function_internal_garbage_collected(self, *args, **kwargs)
2444 args, kwargs = None, None
2445 with self._lock:
-> 2446 graph_function, _, _ = self._maybe_define_function(args, kwargs)
2447 return graph_function
2448
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _maybe_define_function(self, args, kwargs)
2775
2776 self._function_cache.missed.add(call_context_key)
-> 2777 graph_function = self._create_graph_function(args, kwargs)
2778 self._function_cache.primary[cache_key] = graph_function
2779 return graph_function, args, kwargs
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/function.py in _create_graph_function(self, args, kwargs, override_flat_arg_shapes)
2665 arg_names=arg_names,
2666 override_flat_arg_shapes=override_flat_arg_shapes,
-> 2667 capture_by_value=self._capture_by_value),
2668 self._function_attributes,
2669 # Tell the ConcreteFunction to clean up its graph once it goes out of
/opt/conda/lib/python3.6/site-packages/tensorflow/python/framework/func_graph.py in func_graph_from_py_func(name, python_func, args, kwargs, signature, func_graph, autograph, autograph_options, add_control_dependencies, arg_names, op_return_value, collections, capture_by_value, override_flat_arg_shapes)
979 _, original_func = tf_decorator.unwrap(python_func)
980
--> 981 func_outputs = python_func(*func_args, **func_kwargs)
982
983 # invariant: `func_outputs` contains only Tensors, CompositeTensors,
/opt/conda/lib/python3.6/site-packages/tensorflow/python/eager/def_function.py in wrapped_fn(*args, **kwds)
439 # __wrapped__ allows AutoGraph to swap in a converted function. We give
440 # the function a weak reference to itself to avoid a reference cycle.
--> 441 return weak_wrapped_fn().__wrapped__(*args, **kwds)
442 weak_wrapped_fn = weakref.ref(wrapped_fn)
443
/opt/conda/lib/python3.6/site-packages/tensorflow/python/framework/func_graph.py in wrapper(*args, **kwargs)
966 except Exception as e: # pylint:disable=broad-except
967 if hasattr(e, "ag_error_metadata"):
--> 968 raise e.ag_error_metadata.to_exception(e)
969 else:
970 raise
ValueError: in user code:
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:1147 predict_function *
outputs = self.distribute_strategy.run(
/opt/conda/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:951 run **
return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:2290 call_for_each_replica
return self._call_for_each_replica(fn, args, kwargs)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/distribute/distribute_lib.py:2649 _call_for_each_replica
return fn(*args, **kwargs)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py:1122 predict_step **
return self(x, training=False)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py:886 __call__
self.name)
/opt/conda/lib/python3.6/site-packages/tensorflow/python/keras/engine/input_spec.py:180 assert_input_compatibility
str(x.shape.as_list()))
ValueError: Input 0 of layer sequential is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: [32, 2048, 3]