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

Changes make the code work in 2023 #393

Open
PTN407 opened this issue Apr 1, 2023 · 2 comments
Open

Changes make the code work in 2023 #393

PTN407 opened this issue Apr 1, 2023 · 2 comments

Comments

@PTN407
Copy link

PTN407 commented Apr 1, 2023

Hello everyone,
First of all, this is not exactly an issue, but some changes i made to the code so the project work (i tested on kaggle). I haven't test on my computer yet (it's old and can't run those code) (so yet can't make pull requests). I used this in code used in researching so I can't share publicly, sorry.
Code:

import glob
filenames = glob.glob('/kaggle/working/ssd_keras/keras_layers/*.py')
for filename in filenames:
    with open(filename, 'r') as file :
        text = file.read()
    text = text.replace('keras.engine.topology', 'tensorflow.keras.layers')
    text = text.replace('K.image_dim_ordering()', 'K.image_data_format()')
    text = text.replace('._keras_shape', '.shape')
    text = text.replace('.trainable_weights', '._trainable_weights')
    text = text.replace('tf', 'channels_last')
    with open(filename, 'w') as file:
        file.write(text)
with open('/kaggle/working/ssd_keras/keras_loss_function/keras_ssd_loss.py', 'r') as file :
    text = file.read()
text = text.replace('from __future__ import division', '')
with open('/kaggle/working/ssd_keras/keras_loss_function/keras_ssd_loss.py', 'w') as file:
    file.write(text)
with open('/kaggle/working/ssd_keras/keras_loss_function/keras_ssd_loss.py', 'r+') as f:
        content = f.read()
        f.seek(0, 0)
        f.write('from __future__ import division\nimport tensorflow as tf\ntf.to_float = lambda x: tf.cast(x, tf.float32)'.rstrip('\r\n') + '\n' + content)
with open('/kaggle/working/ssd_keras/data_generator/object_detection_2d_data_generator.py', 'r') as file :
    text = file.read()
text = text.replace('yield ret', 'yield tuple(ret)')
with open('/kaggle/working/ssd_keras/data_generator/object_detection_2d_data_generator.py', 'w') as file:
    file.write(text)
with open('/kaggle/working/ssd_keras/eval_utils/average_precision_evaluator.py', 'r') as file :
    text = file.read()
text = text.replace('if len(predictions) == 0:', 
                    'if len(predictions) == 0:\n                cumulative_true_positives.append(1)\n                cumulative_false_positives.append(1)')
with open('/kaggle/working/ssd_keras/eval_utils/average_precision_evaluator.py', 'w') as file:
    file.write(text)
with open('/kaggle/working/ssd_keras/keras_loss_function/keras_ssd_loss.py', 'r') as file :
    text = file.read()
text = text.replace('tf.log', 'tf.math.log')
text = text.replace('self.neg_pos_ratio = tf.constant(self.neg_pos_ratio)', '')
text = text.replace('self.n_neg_min = tf.constant(self.n_neg_min)', '')
text = text.replace('self.alpha = tf.constant(self.alpha)', '')
text = text.replace('tf.count_nonzero', 'tf.math.count_nonzero')
text = text.replace('tf.to_int32(n_positive)', 'tf.cast(n_positive, tf.int32)')
with open('/kaggle/working/ssd_keras/keras_loss_function/keras_ssd_loss.py', 'w') as file:
    file.write(text)
import os
os.environ['PYTHONPATH'] += ':/kaggle/working/ssd_keras/:/kaggle/working/ssd_keras/keras_layers/'
@brunomendes1
Copy link

brunomendes1 commented Jan 21, 2024

This is great. I am trying to get the code to run too.
I will try your changes.

Btw, do we really want to run the line
text = text.replace('tf', 'channels_last')??

@sphinx-suh
Copy link

For information sharing, i am writing this.

  1. ssd7 case, csv file coordinate must be not corner form but minmax form. Almost all of the problems were due to this issue. In def parse_csv, "The expected strings are 'image_name', 'xmin', 'xmax', 'ymin', 'ymax', 'class_id'."

  2. ssd300 case, In evaluation mode, mode must be 'training' not 'inference'

Then, it will work in tensorflow 2.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants