-
Notifications
You must be signed in to change notification settings - Fork 263
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
Added UDF for emotion detection #356
Conversation
d60bed7
to
bb34fd9
Compare
eva/udfs/emotion_detector.py
Outdated
self.model.load_state_dict(model_state["net"]) | ||
|
||
# move to GPU and set to evaluation mode | ||
self.to_device("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.
We shouldn't need this right?
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 without this, I get an error saying input tensors are CUDA but the model is not. I am inheriting AbstractClassifierUDF
and implementing the classify
method.
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.
def to_device(self, device: str):
should have moved the model to GPU. Can you verify if it is called?
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 I tried that. It does not automatically move. to_device()
is not being called.
eva/udfs/emotion_detector.py
Outdated
# load model | ||
self.model = VGG("VGG19") | ||
model_state = torch.load( | ||
os.path.join(EVA_DEFAULT_DIR, "data", "models", "emotion_detector.t7") |
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 we upload this to google drive and pull it from there? It won't work on collab
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.
Oh yes sure, I can do that. But what should the path here be then?
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.
2 points:
- Where is the t7 model file? It is not part of the PR
- @gaurav274 we need a better system of storing model files
@Anirudh58 I shared a link to the Google drive folder. We should also add some test cases. |
Right I'll upload the model to the drive. And yes I'll add a few testcases for this UDF |
eva/udfs/emotion_detector.py
Outdated
self.model.load_state_dict(model_state["net"]) | ||
|
||
# move to GPU and set to evaluation mode | ||
self.to_device("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.
def to_device(self, device: str):
should have moved the model to GPU. Can you verify if it is called?
eva/udfs/emotion_detector.py
Outdated
# predict | ||
ncrops, c, h, w = np.shape(inputs) | ||
inputs = inputs.view(-1, c, h, w) | ||
inputs = inputs.cuda() |
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.
@xzdandy @LordDarkula How will this call work? How to figure which GPU to move the data on?
70c59a9
to
5ddfc0b
Compare
eva/udfs/emotion_detector.py
Outdated
# load model | ||
self.model = VGG("VGG19") | ||
model_state = torch.load( | ||
os.path.join(EVA_DEFAULT_DIR, "data", "models", "emotion_detector.t7") |
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.
2 points:
- Where is the t7 model file? It is not part of the PR
- @gaurav274 we need a better system of storing model files
|
||
|
||
# helper class for VGG | ||
class VGG(nn.Module): |
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.
Under our current system you should be using PytorchAbstractClassifierUDF
which inherists from AbstractClassifierUDF
and nn.Module
already.
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 should be fine as I guess because it is a helper class
from eva.udfs.abstract_udf import AbstractClassifierUDF | ||
from eva.udfs.gpu_compatible import GPUCompatible | ||
|
||
# VGG configuration |
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 kind of configuration is this? Is this the structure of the neural network? A small comment would be nice
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, it specifies the architecture. But yes, let me clean it up a little.
eva/udfs/emotion_detector.py
Outdated
return nn.Sequential(*layers) | ||
|
||
|
||
class EmotionDetector(AbstractClassifierUDF, GPUCompatible): |
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.
We can maybe inherit this from PytorchAbstractClassifierUDF
, and then to_device
should be taken care of automatically.
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 referenced the approach from FaceDetector because it had a lot of pre-processing/trasnforms. But yes, I will try inheriting from PytorchAbstractClassifierUDF
@Anirudh58 @LordDarkula We need to close this PR asap. It is important for the release. What are the missing questions that we need to address? |
5ddfc0b
to
6e87ebe
Compare
6e87ebe
to
5df970b
Compare
We are planning to use this approach for downloading models using Dropbox links -- |
965c07d
to
1a4066b
Compare
@Anirudh58 Are we planning to make the changes Joy mentioned in this PR? |
Sure, that should work. |
1a4066b
to
2e7f755
Compare
No description provided.