shunk031 commited on
Commit
e838a3b
1 Parent(s): b8fead0

Upload AestheticsPredictorV2Linear

Browse files
Files changed (2) hide show
  1. config.json +2 -2
  2. modeling_v2.py +12 -2
config.json CHANGED
@@ -1,10 +1,10 @@
1
  {
2
- "_name_or_path": "openai/clip-vit-large-patch14",
3
  "architectures": [
4
  "AestheticsPredictorV2Linear"
5
  ],
6
  "attention_dropout": 0.0,
7
  "auto_map": {
 
8
  "AutoModel": "modeling_v2.AestheticsPredictorV2Linear"
9
  },
10
  "dropout": 0.0,
@@ -15,7 +15,7 @@
15
  "initializer_range": 0.02,
16
  "intermediate_size": 4096,
17
  "layer_norm_eps": 1e-05,
18
- "model_type": "clip_vision_model",
19
  "num_attention_heads": 16,
20
  "num_channels": 3,
21
  "num_hidden_layers": 24,
 
1
  {
 
2
  "architectures": [
3
  "AestheticsPredictorV2Linear"
4
  ],
5
  "attention_dropout": 0.0,
6
  "auto_map": {
7
+ "AutoConfig": "configuration_predictor.AestheticsPredictorConfig",
8
  "AutoModel": "modeling_v2.AestheticsPredictorV2Linear"
9
  },
10
  "dropout": 0.0,
 
15
  "initializer_range": 0.02,
16
  "intermediate_size": 4096,
17
  "layer_norm_eps": 1e-05,
18
+ "model_type": "aesthetics_predictor",
19
  "num_attention_heads": 16,
20
  "num_channels": 3,
21
  "num_hidden_layers": 24,
modeling_v2.py CHANGED
@@ -97,8 +97,13 @@ class AestheticsPredictorV2ReLU(AestheticsPredictorV2Linear):
97
  def convert_v2_linear_from_openai_clip(
98
  predictor_head_name: str,
99
  openai_model_name: str = "openai/clip-vit-large-patch14",
 
100
  ) -> AestheticsPredictorV2Linear:
101
- model = AestheticsPredictorV2Linear.from_pretrained(openai_model_name)
 
 
 
 
102
 
103
  state_dict = torch.hub.load_state_dict_from_url(
104
  URLS_LINEAR[predictor_head_name], map_location="cpu"
@@ -119,8 +124,13 @@ def convert_v2_linear_from_openai_clip(
119
  def convert_v2_relu_from_openai_clip(
120
  predictor_head_name: str,
121
  openai_model_name: str = "openai/clip-vit-large-patch14",
 
122
  ) -> AestheticsPredictorV2ReLU:
123
- model = AestheticsPredictorV2ReLU.from_pretrained(openai_model_name)
 
 
 
 
124
 
125
  state_dict = torch.hub.load_state_dict_from_url(
126
  URLS_RELU[predictor_head_name], map_location="cpu"
 
97
  def convert_v2_linear_from_openai_clip(
98
  predictor_head_name: str,
99
  openai_model_name: str = "openai/clip-vit-large-patch14",
100
+ config: Optional[AestheticsPredictorConfig] = None,
101
  ) -> AestheticsPredictorV2Linear:
102
+ config = config or AestheticsPredictorConfig.from_pretrained(openai_model_name)
103
+ model = AestheticsPredictorV2Linear(config)
104
+
105
+ clip_model = CLIPVisionModelWithProjection.from_pretrained(openai_model_name)
106
+ model.load_state_dict(clip_model.state_dict(), strict=False)
107
 
108
  state_dict = torch.hub.load_state_dict_from_url(
109
  URLS_LINEAR[predictor_head_name], map_location="cpu"
 
124
  def convert_v2_relu_from_openai_clip(
125
  predictor_head_name: str,
126
  openai_model_name: str = "openai/clip-vit-large-patch14",
127
+ config: Optional[AestheticsPredictorConfig] = None,
128
  ) -> AestheticsPredictorV2ReLU:
129
+ config = config or AestheticsPredictorConfig.from_pretrained(openai_model_name)
130
+ model = AestheticsPredictorV2ReLU(config)
131
+
132
+ clip_model = CLIPVisionModelWithProjection.from_pretrained(openai_model_name)
133
+ model.load_state_dict(clip_model.state_dict(), strict=False)
134
 
135
  state_dict = torch.hub.load_state_dict_from_url(
136
  URLS_RELU[predictor_head_name], map_location="cpu"