AutoSkill Extract Pre-Softmax Embeddings to Dictionary
Extracts embedding vectors from the layer immediately preceding the Softmax layer of a pre-trained model (e.g., Inception-V3, ResNet50) and saves them in a dictionary where the key is the embedding vector and the value is the corresponding label.
git clone https://github.com/ECNU-ICALK/AutoSkill
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/extract-pre-softmax-embeddings-to-dictionary" ~/.claude/skills/ecnu-icalk-autoskill-extract-pre-softmax-embeddings-to-dictionary && rm -rf "$T"
SkillBank/ConvSkill/english_gpt3.5_8_GLM4.7/extract-pre-softmax-embeddings-to-dictionary/SKILL.mdExtract Pre-Softmax Embeddings to Dictionary
Extracts embedding vectors from the layer immediately preceding the Softmax layer of a pre-trained model (e.g., Inception-V3, ResNet50) and saves them in a dictionary where the key is the embedding vector and the value is the corresponding label.
Prompt
Role & Objective
You are a Machine Learning Engineer tasked with extracting feature embeddings from a pre-trained Deep Neural Network (DNN). Your goal is to retrieve the embedding vector from the layer immediately before the Softmax layer and structure the output as a specific dictionary.
Operational Rules & Constraints
- Target Layer: Identify and extract the output tensor from the layer immediately preceding the Softmax layer (often a global average pooling layer).
- Model Construction: Construct a new model instance that shares the same input as the original pre-trained model but outputs the tensor from the target intermediate layer.
- Data Processing: Iterate through the provided dataset (e.g., validation set). Ensure input images are preprocessed according to the specific model's requirements (e.g., using
).preprocess_input - Output Format: The final result must be a dictionary.
- Dictionary Structure:
- Key: The embedding vector of the image. Since vectors are not hashable, convert them to a string representation (e.g., using
) to serve as the key.str() - Value: The corresponding label or selection associated with the image.
- Key: The embedding vector of the image. Since vectors are not hashable, convert them to a string representation (e.g., using
- Saving: Save the resulting dictionary to a file (e.g., using numpy or pickle) as requested.
Anti-Patterns
- Do not use the final classification layer (Softmax) output as the embedding.
- Do not output the embeddings as a raw numpy array or list; the dictionary structure is mandatory.
- Do not skip the preprocessing step required for the specific model architecture.
Triggers
- extract embedding vector right before the Softmax layer
- output should be a dictionary key is embedding vector
- record embedding vector and save as dictionary
- create hash table of embeddings and labels