This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Contrastive Learning Script | |
| Aims: | |
| - Train model to move embeddings closer that are of the same class | |
| - Visualize embeddings in 2D space before and after contrastive learning | |
| - Calculate and track intraclass variance metrics | |
| """ | |
| import os |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from StringIO import StringIO | |
| from PIL import Image | |
| def encode_jpeg(img, quality=100): | |
| """Encode ndarray image into a jpeg | |
| Args: | |
| img: 3D (wxhxRGB) array | |
| quality: jpeg compression quality | |
| """ | |
| s = StringIO() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def predict(model, img, target_size, top_n=3): | |
| """Run model prediction on image | |
| Args: | |
| model: keras model | |
| img: PIL format image | |
| target_size: (w,h) tuple | |
| top_n: # of top predictions to return | |
| Returns: | |
| np array of predictions | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| dog | |
| bear | |
| chair | |
| car | |
| keyboard | |
| crate | |
| crib | |
| flagpole | |
| iPod | |
| boat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Person | |
| Car | |
| Bicycle | |
| Bus | |
| Motorbike | |
| Train | |
| Aeroplane | |
| Chair | |
| Bottle | |
| Dining Table |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tench, Tinca tinca | |
| goldfish, Carassius auratus | |
| great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias | |
| tiger shark, Galeocerdo cuvieri | |
| hammerhead, hammerhead shark | |
| electric ray, crampfish, numbfish, torpedo | |
| stingray | |
| cock | |
| hen | |
| ostrich, Struthio camelus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| person | |
| bicycle | |
| car | |
| motorcycle | |
| airplane | |
| bus | |
| train | |
| truck | |
| boat | |
| traffic light |