-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
adding resnet18 support #694
base: main
Are you sure you want to change the base?
Conversation
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.
Hi @cl3m3nt,
Thanks for sending this over. It looks good partially but some bits missing:
- You don't seem to have the newest version of
dev
- can you please re-base your branch? - Do you have an IDE which shows pep-8 compatibility (like PyCharm etc). There are a lot of non-compliant format issues, which these IDEs will automatically fix for you.
- There is an import error in the CI, you should have that locally too, which version of TF do you use locally?
- Can you please add a test into
test_keras.py
that shows the model is working?
|
||
def resnet18_default_n_linear(num_outputs, input_shape=(120,60,3)): | ||
|
||
# Instantiate a ResNet18 model |
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.
Instead of a comment, please rather provide a doctoring.
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 is a doctoring :) ?
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.
That's a typo (autocomplete :-) meant to be 'docstring'.
from tensorflow.keras.layers import Activation, Dropout, Flatten | ||
from tensorflow.keras.layers import LSTM | ||
from tensorflow.keras.layers import TimeDistributed as TD | ||
from tensorflow.keras.layers import Conv3D, MaxPooling3D, Conv2DTranspose | ||
from tensorflow.keras.backend import concatenate | ||
from tensorflow.keras.models import Model, Sequential | ||
from donkeycar.parts.keras_resnet18 import identity_block,conv_block,ResNet18 |
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 line falls over in the CI, please also use pep-8 formatting
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.
Any guess why it falls over in CI ?
Might be related to keras_resnet18 import
'from keras_applications.imagenet_utils' ?
utils = tf.keras.utils | ||
|
||
|
||
def resnet18_default_n_linear(num_outputs, input_shape=(120,60,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.
As you already made a new module for the new model, pls put those functions there.
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 do you mean here ? Do you recommend to move resnet18 function and classes to keras_resnet18 module ?
def resnet18_default_n_linear(num_outputs, input_shape=(120,60,3)): | ||
|
||
# Instantiate a ResNet18 model | ||
resnet18 = ResNet18(include_top=False,weights='cifar100_coarse',input_shape=input_shape,backend=backend,layers=layers,models=models,utils=utils) |
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 use pep-8 line length and formatting.
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
img_arr = img_arr.reshape((1,) + img_arr.shape) | ||
outputs = self.model.predict(img_arr) | ||
steering = outputs[0] | ||
return steering[0] , dk.utils.throttle(steering[0]) |
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 is the behaviour of KerasInferred
, KerasLinear
returns steering
and throttle
independently.
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.
Yes you are right, I'll fix this following KerasLinear.
name = conv_name_base + '2b')(x) | ||
x = BatchNormalization(axis=bn_axis,name=bn_name_base+'2b')(x) | ||
x = Activation('relu')(x) | ||
|
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.
here too.
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
|
||
|
||
x = Convolution2D(filters2, kernel_size, | ||
padding='same', |
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.
Indention: pep-8.
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
pooling=None, | ||
classes=20, | ||
**kwargs): | ||
global backend, layers, models, keras_utils |
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 try to avoid global variables. If yo need to share them between functions it's fine to put them into a class.
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 followed here what keras_team did for resnet50
https://github.com/keras-team/keras-applications/blob/master/keras_applications/resnet50.py
|
||
def identity_block(input_tensor, kernel_size, filters, stage, block): | ||
filters1, filters2 = filters | ||
if backend.image_data_format() == 'channels_last': |
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 following code seems to re-appear a couple of times, maybe factor this into a small helper function.
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.
Yes, same here I followed what keras-team did for resnet50.
There a 2 occurences of the same code, which could be acceptable don't you think ?
@@ -4,136 +4,117 @@ | |||
Basic usage should feel familiar: python train_v2.py --model models/mypilot | |||
|
|||
Usage: | |||
train.py [--tubs=tubs] (--model=<model>) [--type=(linear|inferred|tensorrt_linear|tflite_linear)] | |||
train.py [--tubs=tubs] (--model=<model>) [--type=(linear|inferred|tensorrt_linear|tflite_linear|tflite_r18_lin|tflite_r18_cat)] | |||
|
|||
Options: | |||
-h --help Show this screen. | |||
""" | |||
|
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.
You don't have the HEAD revision of the dev
branch, this file is now only a small script supported for backward compatibility.
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 double check then how you train within the HEAD revision.
Hi @cl3m3nt - do you still want to pursue this? We have a reset 18 in pytorch now, but there is no harm having this in tf, too? |
@cl3m3nt this looks great and I believe a lot of people would like to see this merged. Do you have time to work on this? |
We already have Resnet18 with PyTorch now. FYI |
Thanks @sctse999. |
Thanks @tikurahul for the heads up. |
Great I would love to see resnet18 or mobilenetv2 on keras as well. |
Adding pre-trained Resnet18 model for transfer learning.
Model has been trained using CIFAR100 coarse (20 super classes).
Changes are the following: