Commit
·
302d684
1
Parent(s):
62c06e0
tf keras issues again
Browse files- requirements.txt +1 -0
- src/nets/Loss.py +1 -1
- src/nets/mobilenet.py +3 -3
- src/nets/resnet50.py +3 -3
- src/nets/vgg16.py +2 -2
- src/utils/callbacks.py +5 -4
- src/utils/dataloader.py +2 -2
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
streamlit
|
2 |
numpy
|
3 |
tensorflow
|
|
|
4 |
Pillow
|
|
|
1 |
streamlit
|
2 |
numpy
|
3 |
tensorflow
|
4 |
+
keras
|
5 |
Pillow
|
src/nets/Loss.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import tensorflow as tf
|
2 |
-
from
|
3 |
|
4 |
def multi_category_focal_loss2(gamma=2., alpha=1):
|
5 |
"""
|
|
|
1 |
import tensorflow as tf
|
2 |
+
from keras import backend as K
|
3 |
|
4 |
def multi_category_focal_loss2(gamma=2., alpha=1):
|
5 |
"""
|
src/nets/mobilenet.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
from
|
2 |
-
from
|
3 |
DepthwiseConv2D, Dropout, GlobalAveragePooling2D,
|
4 |
Input, Reshape)
|
5 |
-
from
|
6 |
|
7 |
|
8 |
def _conv_block(inputs, filters, alpha, kernel=(3, 3), strides=(1, 1)):
|
|
|
1 |
+
from keras import backend as K
|
2 |
+
from keras.layers import (Activation, BatchNormalization, Conv2D,
|
3 |
DepthwiseConv2D, Dropout, GlobalAveragePooling2D,
|
4 |
Input, Reshape)
|
5 |
+
from keras.models import Model
|
6 |
|
7 |
|
8 |
def _conv_block(inputs, filters, alpha, kernel=(3, 3), strides=(1, 1)):
|
src/nets/resnet50.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
from
|
2 |
-
from
|
3 |
Conv2D, Dense, Flatten, Input, MaxPooling2D,
|
4 |
ZeroPadding2D)
|
5 |
-
from
|
6 |
|
7 |
|
8 |
def identity_block(input_tensor, kernel_size, filters, stage, block):
|
|
|
1 |
+
from keras import layers
|
2 |
+
from keras.layers import (Activation, AveragePooling2D, BatchNormalization,
|
3 |
Conv2D, Dense, Flatten, Input, MaxPooling2D,
|
4 |
ZeroPadding2D)
|
5 |
+
from keras.models import Model
|
6 |
|
7 |
|
8 |
def identity_block(input_tensor, kernel_size, filters, stage, block):
|
src/nets/vgg16.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
-
from
|
2 |
-
from
|
3 |
|
4 |
def VGG16(input_shape=None, classes=1000): #def 就是开始定义VGG16的网络
|
5 |
img_input = Input(shape=input_shape) # 224, 224, 3
|
|
|
1 |
+
from keras.layers import Conv2D, Dense, Flatten, Input, MaxPooling2D
|
2 |
+
from keras.models import Model #导入包Conv2D是卷积核 Flatten是展开 Input输入 MaxPooling2D最大卷积核
|
3 |
|
4 |
def VGG16(input_shape=None, classes=1000): #def 就是开始定义VGG16的网络
|
5 |
img_input = Input(shape=input_shape) # 224, 224, 3
|
src/utils/callbacks.py
CHANGED
@@ -5,9 +5,10 @@ matplotlib.use('Agg')
|
|
5 |
from matplotlib import pyplot as plt
|
6 |
import scipy.signal
|
7 |
import tensorflow as tf
|
|
|
8 |
|
9 |
|
10 |
-
class LossHistory(
|
11 |
def __init__(self, log_dir):
|
12 |
import datetime
|
13 |
curr_time = datetime.datetime.now()
|
@@ -59,7 +60,7 @@ class LossHistory(tf.keras.callbacks.Callback):
|
|
59 |
plt.cla()
|
60 |
plt.close("all")
|
61 |
|
62 |
-
class ExponentDecayScheduler(
|
63 |
def __init__(self,
|
64 |
decay_rate,
|
65 |
verbose=0):
|
@@ -71,13 +72,13 @@ class ExponentDecayScheduler(tf.keras.callbacks.Callback):
|
|
71 |
def on_epoch_end(self, batch, logs=None):
|
72 |
lr = self.model.optimizer.learning_rate
|
73 |
try:
|
74 |
-
current_lr =
|
75 |
except Exception:
|
76 |
current_lr = lr
|
77 |
|
78 |
new_lr = current_lr * self.decay_rate
|
79 |
try:
|
80 |
-
|
81 |
except Exception:
|
82 |
print("Warning: Could not set learning rate dynamically.")
|
83 |
|
|
|
5 |
from matplotlib import pyplot as plt
|
6 |
import scipy.signal
|
7 |
import tensorflow as tf
|
8 |
+
import keras
|
9 |
|
10 |
|
11 |
+
class LossHistory(keras.callbacks.Callback):
|
12 |
def __init__(self, log_dir):
|
13 |
import datetime
|
14 |
curr_time = datetime.datetime.now()
|
|
|
60 |
plt.cla()
|
61 |
plt.close("all")
|
62 |
|
63 |
+
class ExponentDecayScheduler(keras.callbacks.Callback):
|
64 |
def __init__(self,
|
65 |
decay_rate,
|
66 |
verbose=0):
|
|
|
72 |
def on_epoch_end(self, batch, logs=None):
|
73 |
lr = self.model.optimizer.learning_rate
|
74 |
try:
|
75 |
+
current_lr = keras.backend.get_value(lr)
|
76 |
except Exception:
|
77 |
current_lr = lr
|
78 |
|
79 |
new_lr = current_lr * self.decay_rate
|
80 |
try:
|
81 |
+
keras.backend.set_value(lr, new_lr)
|
82 |
except Exception:
|
83 |
print("Warning: Could not set learning rate dynamically.")
|
84 |
|
src/utils/dataloader.py
CHANGED
@@ -4,13 +4,13 @@ from random import shuffle
|
|
4 |
import cv2
|
5 |
import tensorflow as tf
|
6 |
import numpy as np
|
7 |
-
from
|
8 |
from PIL import Image
|
9 |
|
10 |
from .utils import cvtColor, preprocess_input
|
11 |
|
12 |
|
13 |
-
class ClsDatasets(
|
14 |
def __init__(self, annotation_lines, input_shape, batch_size, num_classes, train, **kwargs):
|
15 |
super().__init__()
|
16 |
self.annotation_lines = annotation_lines
|
|
|
4 |
import cv2
|
5 |
import tensorflow as tf
|
6 |
import numpy as np
|
7 |
+
from keras.utils import to_categorical
|
8 |
from PIL import Image
|
9 |
|
10 |
from .utils import cvtColor, preprocess_input
|
11 |
|
12 |
|
13 |
+
class ClsDatasets(keras.utils.Sequence):
|
14 |
def __init__(self, annotation_lines, input_shape, batch_size, num_classes, train, **kwargs):
|
15 |
super().__init__()
|
16 |
self.annotation_lines = annotation_lines
|