Change model, still broken
This commit is contained in:
parent
84712a1740
commit
6e6b9b5cd6
16
model.py
16
model.py
@ -42,6 +42,8 @@ class SimpleCNN(object):
|
|||||||
for i in range(2)])
|
for i in range(2)])
|
||||||
|
|
||||||
return tf.map_fn(per_output_tensor, output_tensor)
|
return tf.map_fn(per_output_tensor, output_tensor)
|
||||||
|
truth_tensor = tf.transpose(truth_tensor, perm=(1,2,0))
|
||||||
|
output_tensor = tf.transpose(output_tensor, perm=(1,2,0))
|
||||||
|
|
||||||
# Compute per object IOU values for each square, for each box.
|
# Compute per object IOU values for each square, for each box.
|
||||||
ious = input_output_tensor(self.iou)
|
ious = input_output_tensor(self.iou)
|
||||||
@ -79,7 +81,7 @@ class SimpleCNN(object):
|
|||||||
# The cost of incorrect class guesses, per square.
|
# The cost of incorrect class guesses, per square.
|
||||||
class_cost = tf.map_fn(lambda output:
|
class_cost = tf.map_fn(lambda output:
|
||||||
tf.map_fn(lambda truth:
|
tf.map_fn(lambda truth:
|
||||||
tf.norm(output[2*5:2*5+6]-truth[5:12]), truth_tensor), output_tensor)
|
sum(pow(output[2*5:2*5+6]-truth[5:12],2), axis=0), truth_tensor), output_tensor)
|
||||||
|
|
||||||
# Weights from the YOLO paper.
|
# Weights from the YOLO paper.
|
||||||
coord_weight = 5
|
coord_weight = 5
|
||||||
@ -92,15 +94,15 @@ class SimpleCNN(object):
|
|||||||
noobj_cost= noobj_weight * confidence_cost
|
noobj_cost= noobj_weight * confidence_cost
|
||||||
# Cost per box, selecting only "responsible" entries.
|
# Cost per box, selecting only "responsible" entries.
|
||||||
box_cost = (
|
box_cost = (
|
||||||
obj_cost* cast(eq_max_box, 'float32') +
|
obj_cost* tf.cast(eq_max_box, tf.float32) +
|
||||||
noobj_cost* cast(eq_min_box, 'float32')
|
noobj_cost* tf.cast(eq_min_box, tf.float32)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Cost per square, penalizing only "responsible" squares.
|
# Cost per square, penalizing only "responsible" squares.
|
||||||
square_cost= class_cost * cast(eq_max_square, 'float32')
|
square_cost = class_cost * tf.cast(eq_max_square, tf.float32)
|
||||||
|
|
||||||
# Total cost
|
# Total cost
|
||||||
cost = sum(sum(sum(box_cost))) + sum(sum(square_cost))
|
cost = sum(box_cost) + sum(square_cost)
|
||||||
return cost
|
return cost
|
||||||
|
|
||||||
def build_model(self):
|
def build_model(self):
|
||||||
@ -118,7 +120,7 @@ class SimpleCNN(object):
|
|||||||
self.model.add(Flatten())
|
self.model.add(Flatten())
|
||||||
self.model.add(Dense(units=self.squares*self.squares*(self.boxes*5+self.classes)))
|
self.model.add(Dense(units=self.squares*self.squares*(self.boxes*5+self.classes)))
|
||||||
self.model.add(Reshape((64,-1)))
|
self.model.add(Reshape((64,-1)))
|
||||||
self.model.compile(loss=self.loss, optimizer=Adam(lr=0.5e-4, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0))
|
self.model.compile(loss=self.cost, optimizer=Adam(lr=0.5e-5, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0))
|
||||||
|
|
||||||
def maxpool_layer(self, *args, **kwargs):
|
def maxpool_layer(self, *args, **kwargs):
|
||||||
self.model.add(MaxPooling2D(*args, **kwargs))
|
self.model.add(MaxPooling2D(*args, **kwargs))
|
||||||
@ -143,7 +145,7 @@ def image_generator(source, n):
|
|||||||
|
|
||||||
inputs = []
|
inputs = []
|
||||||
outputs = []
|
outputs = []
|
||||||
for (inp, out) in image_generator('data/test', 100):
|
for (inp, out) in image_generator('data/test', 200):
|
||||||
inputs.append(inp)
|
inputs.append(inp)
|
||||||
outputs.append(out)
|
outputs.append(out)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user