Comments (2)
this is my way to generate the embeddings.
with open(os.path.join(os.path.join(root,'CUB_200_2011'),'images.txt'),'r') as f:
for line in f:
image_id,file_name = line.split()
text_file = file_name.replace('.jpg','.txt')
text_file = text_root + text_file
text_list = []
with open(text_file,'r') as f_text:
for line in f_text:
line = line.encode(encoding='UTF-8',errors='strict')
line = line.replace(b'\xef\xbf\xbd\xef\xbf\xbd',b' ')
line = line.decode('UTF-8','strict')
text_list.append(line)
inputs = tokenizer(text_list, return_tensors="pt",padding="max_length",truncation=True, max_length=32)
outputs = model(**inputs)
embedding_mean = outputs[1].mean(dim=0).reshape(1,-1).detach().numpy()
embedding_full = outputs[1].detach().numpy()
embedding_words = outputs[0].detach().numpy()
data_dict = {
'embedding_mean':embedding_mean,
'embedding_full':embedding_full,
'embedding_words':embedding_words,
}
class_name,image_name = file_name.split('/')
if not os.path.exists(os.path.join(embedding_root,class_name)):
os.makedirs(os.path.join(embedding_root,class_name))
embedding_file_path = os.path.join(os.path.join(embedding_root,class_name),image_name.replace('.jpg','.pickle'))
with open(embedding_file_path,'wb') as f_write:
pickle.dump(data_dict,f_write)
Moreover,bert_embedding is embeding of cub which is generated. Hope it helps you!
from metaformer.
Thanks a lot @dqshuai. Awesome work.
This solved my doubt.
Thank You
from metaformer.
Related Issues (20)
- Training time on inaturalist HOT 1
- About running on one GPU HOT 1
- RuntimeError in HOT 2
- About how to get meta data? HOT 1
- CUDA Version?
- about acc of stanfordcars HOT 5
- Some errata found on the code HOT 2
- meta data HOT 2
- about pre-trained checkpoint
- about the checkpoint without meta info HOT 1
- metadata-generation-failed
- Apex and Cuda Version
- bert_embedding_cub HOT 1
- About how to get meta data?
- model weights for MetaFormer-2 fine tuned on iNat 2018
- Hello, thank you for the achievement I have a problem with using the cub attribute can you provide the run config parameter of the property, thank you very much HOT 1
- For CUB-200 meta data, i wonder know where is the bert_embedding_cub in the link of CUB-200 HOT 1
- Cannot load pretrain metafg_2_inat21_384 HOT 1
- can you provide the pre-train parameters
- TypeError: MetaFG.__init__() got an unexpected keyword argument 'pretrained_cfg' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from metaformer.