Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated code for tensorflow 2.x release #25

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .envrc
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion .pylintrc
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,4 @@ known-third-party=enchant

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
14 changes: 7 additions & 7 deletions config.yaml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ common_parameters:
logging_output_directory_on_host: "/tmp/voc_ssd"

voc:
data_directory: "../../data/VOC2012"
data_directory: "/data/VOC2012"
train_set_path: "ImageSets/Main/train.txt"
validation_set_path: "ImageSets/Main/val.txt"
train_and_validation_set_path: "ImageSets/Main/trainval.txt"
Expand Down Expand Up @@ -45,20 +45,20 @@ vggish_model_configuration:
prediction_heads_order: ["block2_pool", "block3_pool", "block4_pool", "block5_pool"]
block2_pool:
image_downscale_factor: 4
base_bounding_box_sizes: [20, 25]
base_bounding_box_sizes: [25]
aspect_ratios: [0.6, 0.8, 1]
block3_pool:
image_downscale_factor: 8
base_bounding_box_sizes: [30, 40, 50, 60]
base_bounding_box_sizes: [40, 50, 60]
aspect_ratios: [0.6, 0.8, 1]
block4_pool:
image_downscale_factor: 16
base_bounding_box_sizes: [80, 100, 120]
aspect_ratios: [0.4, 0.6, 0.8, 1]
aspect_ratios: [0.6, 0.8, 1]
block5_pool:
image_downscale_factor: 32
base_bounding_box_sizes: [150, 200, 300, 400, 500]
aspect_ratios: [0.4, 0.6, 0.8, 1]
aspect_ratios: [0.6, 0.8, 1]


resnetish_model_configuration:
Expand Down Expand Up @@ -88,5 +88,5 @@ train:
reduce_learning_rate_patience: 2
reduce_learning_rate_factor: 0.1

model_checkpoint_path: "../../data/voc_ssd_models/current_model/"
best_model_checkpoint_path: "../../data/voc_ssd_models/current_model/"
model_checkpoint_path: "/data/voc_ssd_models/current_model.weights.h5"
best_model_checkpoint_path: "/data/voc_ssd_models/current_model/"
2 changes: 1 addition & 1 deletion docker/app.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM tensorflow/tensorflow:2.9.1-gpu

# Install a few necessary need or useful libs and apps
RUN apt update && apt install -y libcairo2-dev wget libgl1
RUN apt update && apt install -y git libcairo2-dev wget libgl1

# Download base tensorflow models
RUN mkdir -p /root/.keras/models && \
Expand Down
Empty file modified net/__init__.py
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions net/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import net.data
import net.plot
import net.ssd
import net.utilities


Expand Down
24 changes: 8 additions & 16 deletions net/ml.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,14 @@ def __init__(self, model_configuration, categories_count):
categories_predictions_heads_ops_list.append(categories_predictions_head)
offset_predictions_heads_ops_list.append(offsets_predictions_head)

self.batch_of_categories_predictions_logits_matrices_op = \
tf.concat(categories_predictions_heads_ops_list, axis=1)
self.batch_of_categories_predictions_logits_matrices_op = tf.keras.layers.Concatenate(
axis=1, name="categories_prediction_logits_head")(categories_predictions_heads_ops_list)

self.batch_of_softmax_categories_predictions_matrices_op = tf.nn.softmax(
logits=self.batch_of_categories_predictions_logits_matrices_op,
axis=-1,
name="categories_predictions_head")
self.batch_of_softmax_categories_predictions_matrices_op = tf.keras.layers.Softmax(
axis=-1, name="categories_predictions_head")(self.batch_of_categories_predictions_logits_matrices_op)

self.batch_of_offsets_predictions_matrices_op = tf.concat(
values=offset_predictions_heads_ops_list,
axis=1,
name="offsets_predictions_head")
self.batch_of_offsets_predictions_matrices_op = tf.keras.layers.Concatenate(
axis=1, name="offsets_predictions_head")(offset_predictions_heads_ops_list)

self.model = tf.keras.models.Model(
inputs=self.input_placeholder,
Expand Down Expand Up @@ -144,13 +140,9 @@ def get_predictions_head(input_op, categories_count, head_configuration):
offsets_predictions_op = tf.keras.layers.Conv2D(
filters=4 * default_boxes_count, kernel_size=(3, 3), padding='same')(x)

# Reshape outputs to 3D matrices (batch_dimension, default boxes on all pixel locations, x), where
# x is categories_count for categories logits predictions op and 4 for offsets predictions op
return \
tf.reshape(categories_logits_predictions_op,
shape=(tf.shape(categories_logits_predictions_op)[0], -1, categories_count)), \
tf.reshape(offsets_predictions_op,
shape=(tf.shape(offsets_predictions_op)[0], -1, 4))
tf.keras.layers.Reshape((-1, categories_count))(categories_logits_predictions_op), \
tf.keras.layers.Reshape((-1, 4))(offsets_predictions_op)

def get_base_layers_tensors_map(self):
"""
Expand Down
11 changes: 7 additions & 4 deletions net/plot.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ def draw_annotation_label(pil_image, annotation, color, font):

draw_manager = PIL.ImageDraw.Draw(pil_image)

text_size = draw_manager.textsize(annotation.label, font)
dummy_text_box = draw_manager.textbbox((0, 0), annotation.label, font)

text_width = dummy_text_box[2] - dummy_text_box[0]
text_height = dummy_text_box[3] - dummy_text_box[1]

box_left = int(max(0, np.floor(annotation.bounding_box[0] + 0.5)))
box_top = int(max(0, np.floor(annotation.bounding_box[1] + 0.5)))

text_origin = [box_left, box_top - text_size[1]] \
if box_top - text_size[1] >= 0 else [box_left, box_top + 1]
text_origin = [box_left, box_top - text_height] \
if box_top - text_height >= 0 else [box_left, box_top + 1]

text_end = text_origin[0] + text_size[0], text_origin[1] + text_size[1]
text_end = text_origin[0] + text_width, text_origin[1] + text_height
text_box = text_origin[0], text_origin[1], text_end[0], text_end[1]

draw_manager.rectangle(text_box, fill=tuple(color))
Expand Down
Empty file modified net/ssd.py
100644 → 100755
Empty file.
Empty file modified net/utilities.py
100644 → 100755
Empty file.
92 changes: 47 additions & 45 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,97 +1,99 @@
absl-py==1.0.0
antlr4-python3-runtime==4.9.3
astroid==2.12.13
astroid==3.2.4
asttokens==2.4.1
astunparse==1.6.3
attrs==22.1.0
cachetools==5.1.0
certifi==2019.11.28
chardet==3.0.4
colorama==0.4.6
contourpy==1.0.6
cycler==0.11.0
contourpy==1.1.1
cycler==0.12.1
dbus-python==1.2.16
dill==0.3.6
exceptiongroup==1.0.4
dill==0.3.9
exceptiongroup==1.2.2
executing==2.1.0
flatbuffers==1.12
fonttools==4.38.0
future==0.18.2
fonttools==4.55.0
gast==0.4.0
gitdb==4.0.10
GitPython==3.1.29
gitdb==4.0.11
GitPython==3.1.43
google-auth==2.6.6
google-auth-oauthlib==0.4.6
google-pasta==0.2.0
grpcio==1.46.3
h5py==3.6.0
icecream==2.1.3
idna==2.8
imageio==2.22.4
imageio==2.35.1
imgaug==0.4.0
importlib-metadata==4.11.4
iniconfig==1.1.1
invoke==1.7.3
isort==5.10.1
importlib-resources==6.4.5
iniconfig==2.0.0
invoke==2.2.0
isort==5.13.2
keras==2.9.0
Keras-Preprocessing==1.1.2
kiwisolver==1.4.4
lazy-object-proxy==1.8.0
kiwisolver==1.4.7
lazy-loader==0.4
libclang==14.0.1
mando==0.6.4
mando==0.7.1
Markdown==3.3.7
matplotlib==3.6.2
matplotlib==3.7.5
mccabe==0.7.0
networkx==2.8.8
networkx==3.1
numpy==1.22.4
oauthlib==3.2.0
omegaconf==2.2.3
opencv-python==4.6.0.66
opencv-python-headless==4.6.0.66
omegaconf==2.3.0
opencv-python==4.10.0.84
opt-einsum==3.3.0
packaging==21.3
pandas==1.5.2
Pillow==9.3.0
platformdirs==2.5.4
pluggy==1.0.0
pandas==2.0.3
pillow==10.4.0
platformdirs==4.3.6
pluggy==1.5.0
protobuf==3.19.4
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycairo==1.23.0
pycodestyle==2.10.0
pycodestyle==2.12.1
pygments==2.18.0
PyGObject==3.36.0
pylint==2.15.7
pylint==3.2.7
pyparsing==3.0.9
pytest==7.2.0
pytest==8.3.3
python-apt==2.0.0+ubuntu0.20.4.7
python-dateutil==2.8.2
pytz==2022.6
python-dateutil==2.9.0.post0
pytz==2024.2
PyWavelets==1.4.1
PyYAML==6.0
radon==5.1.0
PyYAML==6.0.2
radon==6.0.1
requests==2.22.0
requests-oauthlib==1.3.1
requests-unixsocket==0.2.0
rsa==4.8
scikit-image==0.19.3
scipy==1.9.3
seaborn==0.12.1
Shapely==1.8.5.post1
scikit-image==0.21.0
scipy==1.10.1
seaborn==0.13.2
shapely==2.0.6
six==1.14.0
smmap==5.0.0
smmap==5.0.1
tensorboard==2.9.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.1
tensorflow==2.9.1
tensorflow-estimator==2.9.0
tensorflow-io-gcs-filesystem==0.26.0
termcolor==1.1.0
tifffile==2022.10.10
tomli==2.0.1
tomlkit==0.11.6
tqdm==4.64.1
tifffile==2023.7.10
tomli==2.2.1
tomlkit==0.13.2
tqdm==4.67.1
typing-extensions==4.2.0
tzdata==2024.2
urllib3==1.25.8
visual-logging==1.0
Werkzeug==2.1.2
wrapt==1.14.1
xenon==0.9.0
xmltodict==0.13.0
xenon==0.9.3
xmltodict==0.14.2
zipp==3.8.0
Empty file modified setup.cfg
100644 → 100755
Empty file.
Empty file modified tests/__init__.py
100644 → 100755
Empty file.
Empty file modified tests/commit_stage/__init__.py
100644 → 100755
Empty file.
Empty file modified tests/commit_stage/unit_tests/__init__.py
100644 → 100755
Empty file.
Empty file modified tests/commit_stage/unit_tests/test_utilities.py
100644 → 100755
Empty file.