Commit c1895ed8 authored by mihaivanea's avatar mihaivanea
Browse files

Still working on image processing to feed into the model

parent 98b97c80
......@@ -15,7 +15,7 @@ from PIL import Image
path = "../fddb/FDDB-folds/FDDB-fold-01-ellipseList.txt"
def convert_to_cartesian(ellip_array):
result = []
cartesian_output = []
for ellip in ellip_array:
ellip = [e for e in ellip.rstrip('\n').split(' ')]
major_r = float(ellip[0])
......@@ -27,8 +27,8 @@ def convert_to_cartesian(ellip_array):
x2 = c_x + minor_r
y2 = c_y + major_r
box = [round(p, 4) for p in (x1, y1, x2, y2)]
result.append(box)
return result
cartesian_output.append(box)
return cartesian_output
def generate_arrays_fddb(path):
no_labels, labels = (l for l in benchmark.tokenise(path))
......@@ -42,12 +42,37 @@ def generate_arrays_fddb(path):
if len(data.shape) == 3:
yield data, convert_to_cartesian(lb[2])
def load_arrays_fddb(path):
no_labels, labels = [l for l in benchmark.tokenise(path)]
x = []
y = []
for lb in labels:
img = lb[0]
img_path = "../fddb/" + img + ".jpg"
img = Image.open(img_path)
img = img.resize((224, 224), Image.ANTIALIAS)
img.load()
data = np.asarray(img, dtype="float32")
if len(data.shape) == 3:
x.append(data)
y.append(convert_to_cartesian(lb[2]))
x = np.array(x)
print(x.shape)
y = np.array(y)
print(y.shape)
return x
#generator = generate_arrays_fddb(path)
#
#for g in generator:
# print(g)
# break
#print("DONE")
#
#for g in generator:
# print(g)
#print("DONE")
load_arrays_fddb(path)
......@@ -31,24 +31,24 @@ model.compile(optimizer='rmsprop', loss='categorical_crossentropy')
fddb_path = "../fddb/FDDB-folds/FDDB-fold-01-ellipseList.txt"
## train the model on the new data for a few epochs
#try:
# model.fit_generator(
# generator=generate_arrays_fddb(fddb_path),
# steps_per_epoch=1000, epochs=10
# )
#except Exception as e:
# print(e)
try:
model.fit_generator(
generator=generate_arrays_fddb(fddb_path),
steps_per_epoch=1000, epochs=10
)
except Exception as e:
print(e)
# at this point, the top layers are well trained and we can start fine-tuning
# convolutional layers from inception V3. We will freeze the bottom N layers
# and train the remaining top layers.
# let's visualize layer names and layer indices to see how many layers
# we should freeze:
print(base_model.input_shape)
print(base_model.output_shape)
for i, layer in enumerate(base_model.layers):
print(i, layer.name)
print(base_model.output)
## let's visualize layer names and layer indices to see how many layers
## we should freeze:
#print(base_model.input_shape)
#print(base_model.output_shape)
#for i, layer in enumerate(base_model.layers):
# print(i, layer.name)
#print(base_model.output)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment