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

Added UDF for emotion detection #356

Merged
merged 6 commits into from
Sep 22, 2022

Conversation

Anirudh58
Copy link
Collaborator

No description provided.

self.model.load_state_dict(model_state["net"])

# move to GPU and set to evaluation mode
self.to_device("0")
Copy link
Member

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?

Copy link
Collaborator Author

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.

Copy link
Member

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?

Copy link
Collaborator Author

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.

# load model
self.model = VGG("VGG19")
model_state = torch.load(
os.path.join(EVA_DEFAULT_DIR, "data", "models", "emotion_detector.t7")
Copy link
Member

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

Copy link
Collaborator Author

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?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 points:

  1. Where is the t7 model file? It is not part of the PR
  2. @gaurav274 we need a better system of storing model files

@jarulraj
Copy link
Member

@Anirudh58 I shared a link to the Google drive folder. We should also add some test cases.

@Anirudh58
Copy link
Collaborator Author

@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

self.model.load_state_dict(model_state["net"])

# move to GPU and set to evaluation mode
self.to_device("0")
Copy link
Member

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?

# predict
ncrops, c, h, w = np.shape(inputs)
inputs = inputs.view(-1, c, h, w)
inputs = inputs.cuda()
Copy link
Member

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?

@Anirudh58 Anirudh58 force-pushed the movie_analysis branch 2 times, most recently from 70c59a9 to 5ddfc0b Compare September 13, 2022 18:29
# load model
self.model = VGG("VGG19")
model_state = torch.load(
os.path.join(EVA_DEFAULT_DIR, "data", "models", "emotion_detector.t7")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 points:

  1. Where is the t7 model file? It is not part of the PR
  2. @gaurav274 we need a better system of storing model files



# helper class for VGG
class VGG(nn.Module):
Copy link
Collaborator

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.

Copy link
Member

@gaurav274 gaurav274 Sep 14, 2022

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
Copy link
Collaborator

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

Copy link
Collaborator Author

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.

return nn.Sequential(*layers)


class EmotionDetector(AbstractClassifierUDF, GPUCompatible):
Copy link
Member

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.

Copy link
Collaborator Author

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

@gaurav274
Copy link
Member

gaurav274 commented Sep 15, 2022

@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?

@jarulraj
Copy link
Member

jarulraj commented Sep 17, 2022

We are planning to use this approach for downloading models using Dropbox links --
https://github.com/Emilien-mipt/fer-pytorch/blob/main/fer_pytorch/pre_trained_models.py#L12

@gaurav274 @LordDarkula

@gaurav274
Copy link
Member

gaurav274 commented Sep 18, 2022

@Anirudh58 Are we planning to make the changes Joy mentioned in this PR?
We can also pass the model_dir in the torch.utils.model_zoo.load_url function. How about we keep all these models in the ~/.eva/udfs/models/? @LordDarkula @jarulraj

@jarulraj
Copy link
Member

@Anirudh58 Are we planning to make the changes Joy mentioned in this PR? We can also pass the model_dir in the torch.utils.model_zoo.load_url function. How about we keep all these models in the ~/.eva/udfs/models/? @LordDarkula @jarulraj

Sure, that should work.

@gaurav274 gaurav274 merged commit ebc071d into georgia-tech-db:master Sep 22, 2022
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

Successfully merging this pull request may close these issues.

4 participants