Skip to content

Commit

Permalink
refactoring keras retinanet
Browse files Browse the repository at this point in the history
  • Loading branch information
bw4sz committed Jun 22, 2020
1 parent 68fc565 commit 2fc4bca
Show file tree
Hide file tree
Showing 102 changed files with 42 additions and 56 deletions.
3 changes: 2 additions & 1 deletion deepforest/data/classes.csv
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Tree,0
Dead,0
Alive,1
15 changes: 6 additions & 9 deletions deepforest/deepforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@
from deepforest.retinanet_train import main as retinanet_train
from deepforest.retinanet_train import parse_args

try:
from keras_retinanet import models
from keras_retinanet.models import convert_model
from keras_retinanet.bin.train import create_models
from keras_retinanet.preprocessing.csv_generator import CSVGenerator, _read_classes
from keras_retinanet.utils.eval import evaluate
from keras_retinanet.utils.visualization import draw_box
except:
pass
from deepforest.keras_retinanet import models
from deepforest.keras_retinanet.models import convert_model
from deepforest.keras_retinanet.bin.train import create_models
from deepforest.keras_retinanet.preprocessing.csv_generator import CSVGenerator, _read_classes
from deepforest.keras_retinanet.utils.eval import evaluate
from deepforest.keras_retinanet.utils.visualization import draw_box


class deepforest:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 3 additions & 6 deletions deepforest/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import pandas as pd
import tensorflow as tf

try:
# Retinanet-viz
from keras_retinanet.utils import image as keras_retinanet_image
from keras_retinanet.utils.visualization import draw_detections
except:
pass
# Retinanet-viz
from deepforest.keras_retinanet.utils import image as keras_retinanet_image
from deepforest.keras_retinanet.utils.visualization import draw_detections

def predict_image(model,
image_path=None,
Expand Down
44 changes: 20 additions & 24 deletions deepforest/retinanet_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@
import sys
import warnings

try:
import keras
import keras.preprocessing.image
import tensorflow as tf
except:
pass
try:
# Retinanet
from keras_retinanet import layers
from keras_retinanet import losses
from keras_retinanet import models
from keras_retinanet.callbacks import RedirectModel
from keras_retinanet.callbacks.eval import Evaluate
from keras_retinanet.models.retinanet import retinanet_bbox
from keras_retinanet.preprocessing.csv_generator import CSVGenerator
from keras_retinanet.utils.anchors import make_shapes_callback
from keras_retinanet.utils.config import read_config_file, parse_anchor_parameters
from keras_retinanet.utils.keras_version import check_keras_version
from keras_retinanet.utils.model import freeze as freeze_model
from keras_retinanet.utils.transform import random_transform_generator
from keras_retinanet.utils.image import random_visual_effect_generator
from keras_retinanet.utils.gpu import setup_gpu
except:
pass
import keras
import keras.preprocessing.image
import tensorflow as tf

# Retinanet
from deepforest.keras_retinanet import layers
from deepforest.keras_retinanet import losses
from deepforest.keras_retinanet import models
from deepforest.keras_retinanet.callbacks import RedirectModel
from deepforest.keras_retinanet.callbacks.eval import Evaluate
from deepforest.keras_retinanet.models.retinanet import retinanet_bbox
from deepforest.keras_retinanet.preprocessing.csv_generator import CSVGenerator
from deepforest.keras_retinanet.utils.anchors import make_shapes_callback
from deepforest.keras_retinanet.utils.config import read_config_file, parse_anchor_parameters
from deepforest.keras_retinanet.utils.keras_version import check_keras_version
from deepforest.keras_retinanet.utils.model import freeze as freeze_model
from deepforest.keras_retinanet.utils.transform import random_transform_generator
from deepforest.keras_retinanet.utils.image import random_visual_effect_generator
from deepforest.keras_retinanet.utils.gpu import setup_gpu

from deepforest import tfrecords


Expand Down
9 changes: 3 additions & 6 deletions deepforest/tfrecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
import psutil
import tensorflow as tf

try:
from keras_retinanet import models
from keras_retinanet.preprocessing.csv_generator import CSVGenerator
except:
pass
from deepforest.keras_retinanet import models
from deepforest.keras_retinanet.preprocessing.csv_generator import CSVGenerator


def create_tf_example(image, regression_target, class_target, fname, original_image):
Expand Down Expand Up @@ -248,7 +245,7 @@ def _parse_fn(example):
loaded_image = tf.cast(loaded_image, tf.float32)

# Turn loaded image from rgb into bgr and subtract imagenet means,
# see keras_retinanet.utils.image.preprocess_image
# see deepforest.keras_retinanet.utils.image.preprocess_image
red, green, blue = tf.unstack(loaded_image, axis=-1)

# Subtract imagenet means
Expand Down
8 changes: 3 additions & 5 deletions deepforest/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@
warnings.filterwarnings("ignore", category=FutureWarning)
warnings.filterwarnings("ignore", category=DeprecationWarning)

try:
from keras_retinanet import models
from keras.utils import multi_gpu_model
except:
pass
from deepforest.keras_retinanet import models
from keras.utils import multi_gpu_model

from deepforest import _ROOT


Expand Down
Binary file removed keras_retinanet/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed keras_retinanet/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file removed keras_retinanet/__pycache__/losses.cpython-36.pyc
Binary file not shown.
Binary file removed keras_retinanet/__pycache__/losses.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed keras_retinanet/bin/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file removed keras_retinanet/bin/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file removed keras_retinanet/bin/__pycache__/train.cpython-36.pyc
Binary file not shown.
Binary file removed keras_retinanet/bin/__pycache__/train.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def run(self, *args, **kwargs):

extensions = [
Extension(
'keras_retinanet.utils.compute_overlap',
['keras_retinanet/utils/compute_overlap.pyx']
'deepforest.keras_retinanet.utils.compute_overlap',
['deepforest/keras_retinanet/utils/compute_overlap.pyx']
),
]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_keras_retinanet.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# test loading of keras retinanet
import os
from keras_retinanet.utils.anchors import compute_overlap
from deepforest.keras_retinanet.utils.anchors import compute_overlap
import numpy as np

def test_keras_retinanet():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tfrecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from deepforest import preprocess
from deepforest import tfrecords
from deepforest import utilities
from keras_retinanet import models
from keras_retinanet.preprocessing import csv_generator
from deepforest.keras_retinanet import models
from deepforest.keras_retinanet.preprocessing import csv_generator


# Helper function to check filenames
Expand Down

0 comments on commit 2fc4bca

Please sign in to comment.