-
Notifications
You must be signed in to change notification settings - Fork 1
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
Template of Training Pipeline #1
Conversation
|
||
|
||
def get_gt_boxes(self): | ||
self.gt_boxes = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential place to put annotations for our custom dataset
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
train_od_ex.py
Outdated
matplotlib.use('module://backend_interagg') | ||
|
||
|
||
class RubberDucksTraining: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need DuckTraining at all? How this related to our project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, change names and structure more related to our project w/o some rubber ducks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rubber ducks are quite good as simplest validation dataset
@dupeljan Please, consider aligning training with my proposal data loader from kp/data branch. It's more appropriate to build a dataset separately. The proposal function will return ready-to-go for loop TensorFlow datasets |
@kprokofi it's the simplest use case of standard tensorwlow od model training. Now it's your turn to allingn chosen dataset to this pipeline (it's not a big deal) |
self.finetune() | ||
self.test() | ||
|
||
def load_dataset(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change behavior of this function to load tf dataset. Will I? Anyway, I have a question. For what reason, we need to load images in numpy arrays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the only reason for that is pyplot visualization I suggest removing it and move visualization to another script if you need this because I created a function to load data exactly in tf representation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it only an example. I'll remove it and when you will add appropriate tf loader instead. I can't test pipeline without this method
zero_indexed_groundtruth_classes, self.num_classes)) | ||
print('Done prepping data.') | ||
|
||
def visualize_np(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, do we have two visualization functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's exist to visualize images in numpy ^)
configs = config_util.get_configs_from_pipeline_file(pipeline_config) | ||
model_config = configs['model'] | ||
model_config.ssd.num_classes = num_classes | ||
model_config.ssd.freeze_batchnorm = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we freezing batch normalization for fine-tuning?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion of official tf tutorial. We can ignore it and tune whatever we want
# restore the box regression head but initialize the classification head | ||
# from scratch (we show the omission below by commenting out the line that | ||
# we would add if we wanted to restore both heads) | ||
fake_box_predictor = tf.compat.v2.train.Checkpoint( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why do we need some fake heads and stuff below? Actually, all we need to do is to load weights for the backbone and initialize a new head for classification. Don't we? Or these weird and non-intuitive steps are required by TensorFlow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird way to load model from checkpoint without classification head. TF checkpoints is really difficult to load partially thus this hack exist
train_od_ex.py
Outdated
# These parameters can be tuned; since our training set has 5 images | ||
# it doesn't make sense to have a much larger batch size, though we could | ||
# fit more examples in memory if we wanted to. | ||
batch_size = 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hardcoded numbers. Please, do it in a more explicit way. As a last resort, make global variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll make an attributes
prefixes_to_train = [ | ||
'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalBoxHead', | ||
'WeightSharedConvolutionalBoxPredictor/WeightSharedConvolutionalClassHead'] | ||
for var in trainable_variables: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that we fine-tune only heads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, we have to inspect graph. But I think it tunes only head, yeah. We can choose layers whatever we want
ckpt.restore(checkpoint_path).expect_partial() | ||
|
||
# Run model through a dummy image so that variables are created | ||
image, shapes = self.detection_model.preprocess(tf.zeros([1, 640, 640, 3])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the preprocess function? It's important for me to know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read line https://github.com/kprokofi/animal-recognition-with-voice/pull/1/files#diff-dd1d550d71fd1ed9372fc1021bad76848d71ab8ca4e72ab35c6a14c4ba3a980dR147. It's way to initialize operation shapes
import tensorflow as tf | ||
from object_detection.utils import visualization_utils as viz_utils | ||
|
||
def load_image_into_numpy_array(path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another function to load data to NumPy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It loads single image
return np.array(image.getdata()).reshape( | ||
(im_height, im_width, 3)).astype(np.uint8) | ||
|
||
def plot_detections(image_np, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The third function for visualization? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function quite useful because it visualize bounding boxes on images
No description provided.