{"id":13738389,"url":"https://github.com/YontiLevin/Embeddings2Image","last_synced_at":"2025-05-08T16:33:55.129Z","repository":{"id":37601538,"uuid":"85202569","full_name":"YontiLevin/Embeddings2Image","owner":"YontiLevin","description":"create \"Karpathy's style\" 2d images out of your image embeddings","archived":false,"fork":false,"pushed_at":"2022-12-27T15:34:03.000Z","size":19517,"stargazers_count":66,"open_issues_count":4,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-12T22:57:35.666Z","etag":null,"topics":["python","tsne","umap","visualization"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YontiLevin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-16T14:03:57.000Z","updated_at":"2024-05-30T06:14:30.000Z","dependencies_parsed_at":"2023-01-31T04:16:45.643Z","dependency_job_id":null,"html_url":"https://github.com/YontiLevin/Embeddings2Image","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YontiLevin%2FEmbeddings2Image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YontiLevin%2FEmbeddings2Image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YontiLevin%2FEmbeddings2Image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YontiLevin%2FEmbeddings2Image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YontiLevin","download_url":"https://codeload.github.com/YontiLevin/Embeddings2Image/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224746693,"owners_count":17363092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","tsne","umap","visualization"],"created_at":"2024-08-03T03:02:20.908Z","updated_at":"2024-11-15T07:31:01.773Z","avatar_url":"https://github.com/YontiLevin.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Embeddings2Image\n#### former -\u003e visualize-tsne\nThis small project is for creating 2d images out of the embeddings of the images.   \nIt was inspired by [Andrej Karpathy's blog post](http://cs.stanford.edu/people/karpathy/cnnembed/) on the visualization of CNNs using t-sne.  \n(this guy is pretty sharp :wink: - you should definitely follow him! ).  \n\n**UPDATE #1**  \nAt first the package only supported dimension reduction using **t-sne** but now it also support the great **umap**.  \nCheck it out [https://github.com/lmcinnes/umap](https://github.com/lmcinnes/umap)\n\n**UPDATE #2**  \nI saw that the project is useful to some people so I uploaded it to PyPI for easier integration. \n\n**UPDATE #3**  \nCheckout the [end2end example](examples/end2end.py) added by @nivha \n\n## Examples\n\u003cp align='center'\u003e\n\u003cimg src=\"/examples/mnist2d.jpg\" alt=\"Image of mnist 2d grid via TSNE\" width=\"250\" height=\"250\"/\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u003cimg src=\"/examples/mnistscatter.jpg\" alt=\"Image of mnist scatter via TSNE\" width=\"250\" height=\"250\"/\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u003cimg src=\"/examples/umapmnistscatter.jpg\" alt=\"Image of mnist scatter via UMAP\" width=\"250\" height=\"250\"/\u003e\n\u003cbr/\u003e\nmnist TSNE grid example\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\nmnist TSNE scatter example\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\nmnist UMAP scatter example\n\u003c/p\u003e\n\u003cbr/\u003e\n\u003cp align='center'\u003e\n\u003cimg src=\"/examples/cifar10_grid.jpg\" alt=\"cifar10 grid example\" width=\"300\" height=\"300\"/\u003e\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u003cimg src=\"/examples/cifar10_scatter.jpg\" alt=\"cifar10 scatter example\" width=\"300\" height=\"300\"/\u003e\n\u003cbr/\u003e\ncifar10 grid image example\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\ncifar10 scatter image example\n\u003c/p\u003e\n\n## Installation\n1. via pip\n    1. ```pip install Embeddings2Image```\n2. Download / Clone   \n    1. install - ```python setup.py install```  \n    2. Or just use it as is  \n        1. ```pip install -r requirements.txt```  \n        2. see documentation below    \n\n## Usage\n\n### if installed via PyPI\n```python\nfrom e2i import EmbeddingsProjector  \n \nimage = EmbeddingsProjector()\nimage.path2data = 'data.hdf5'\nimage.load_data()\nimage.calculate_projection()\nimage.create_image()\n```\n#### important! the module expects an hdf5 file with 2 datasets:   \n * urls - datasets which contain the path/url of each image    \n * vectors - dataset which contains the corresponding vector for each image.           \n             make sure that they are both ordered alike\n * checkout this [hdf5 example](examples/create_hdf5_example.py)\n\n#### another option is to load the data and urls explicitly:     \n * urls - create a np.asarray out of a url list and load to image.image_list    \n * vectors - create a np.ndarray of the vectors and load to image.data_vectors   \n \n### if cloned - you can use it from the cmd\n```\nroot@yonti:~/github/Embeddings2|Image$ python cmd.py -h\nusage: cmd.py [-h] -d PATH2DATA [-n OUTPUT_NAME] [-t OUTPUT_TYPE]\n              [-s OUTPUT_SIZE] [-i EACH_IMG_SIZE] [-c BG_COLOR] [--no-shuffle]\n              [--no-sklearn] [--no-svd] [-b BATCH_SIZE]\n\nCreating 2d images out of the embeddings ot the images\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -d PATH2DATA, --path2data PATH2DATA\n                        Path to the hdf5 file   \n  -n OUTPUT_NAME, --output_name OUTPUT_NAME\n                        output image name. Default is tsne_scatter/grid.jpg\n  -t OUTPUT_TYPE, --output_type OUTPUT_TYPE\n                        the type of the output images (scatter/grid)\n  -s OUTPUT_SIZE, --output_size OUTPUT_SIZE\n                        output image size (default=2500)\n  -i EACH_IMG_SIZE, --img_size EACH_IMG_SIZE\n                        each image size (default=50)\n  -c BG_COLOR, --background BG_COLOR\n                        choose output background color (black/white)\n  --no-shuffle          use this flag if you don't want to shuffle\n  --method              chose which method to use for projection.\n                        umap(default) / sklearn - for sklearn's tsne / matten\n                        - for his implementation of tsne\n  --no-svd              it is better to reduce the dimension of long dense\n                        vectors to a size of 50 or smallerbefore computing the\n                        tsne.use this flag if you don't want to do so\n  -b BATCH_SIZE, --batch_size BATCH_SIZE\n                        for speed/memory size errors consider using just a\n                        portion of your data (default=all)\n\nroot@yonti:~/github/visualize-tsne$ python cmd.py -d /home/data/data.hdf5 -i 50 -s 4000 -n test \n```\n\n### full usage options\n\n```python\n# the folowing have both getter and setter\nimage.path2doc # getter \nimage.path2doc = '/home/data/data.hdf5' # setter -\u003e expects string and correct path to an hdf5 file\n\nimage.output_img_name  #  getter\nimage.output_img_name = 'be_creative'  # expects string. default is 'tsne'\n                                       # don't add the file type - jpg is set automatically\n                                       # also the image type(scatter/grid) is added automatically\nimage.output_img_type  #  getter\nimage.output_img_type = 'grid' # expects string. default is 'scatter'. set grid to this way.\n\nimage.output_img_size  #  getter\nimage.output_img_size =  2500  # expects int. default is 2500. \n                               # all images are squared so it means 2500x2500 img.\n                               # also the image type(scatter/grid) is added automatically\n\nimage.each_img_size    #  getter\nimage.each_img_size =  50      # expects int. default is 50. \n                               # the output looks better when constructed with squared images\n                               # but can also handle rects\n                               \nimage.image_list       #  getter\nimage.image_list = img_list    # expects numpy array of strings. \n                               # this is filled up automatically when load_data is called.\n                               # set this explicitly only if you dont load your data from \n                               # an hdf5 file\n\nimage.data_vectors      #  getter\nimage.data_vectors = data       # expects numpy ndarray of dense vectors. \n                               # this is filled up automatically when load_data is called.\n                               # set this explicitly only if you dont load your data from \n                               # an hdf5 file\n\nimage.batch_size       #  getter\nimage.batch_size =  5000       # expects int. default is 0 which means that all images are taken\n                               # use this when you have memory issues. \n                               # it will shuffle your data and take only a subset in order to \n                               # compute the tsne. \n\nimage.method       #  getter\nimage.method =  'maaten'       # expects string. default is 'umap'.\n                               # it is both effiecient in time and ,to my naked eye, seperates the clusters better. \n                               # the other options are 'sklearn' and 'maaten'\n                               # this sets the tsne method to sklearn.tsne vs python version\n                               # of Maaten's tsne.\n                               # i guess they both do the same but didn't fully check it \n                               # so i left it as an option\n\nimage.background_color         #  getter\nimage.background_color =  'white'  # expects string. default is 'black'. the other option is 'white'\n                                        \nimage.tsne_vectors      #  getter\nimage.tsne_vectors = data       # expects numpy ndarray of dense 2d vectors. \n                               # this is filled up automatically when \n                               # image.calaculate_tsne is called.\n                               # set this explicitly only if you have already the tsne vectors\n\n# the followings are methods\nimage.load_data()  #  opens the file which path2file point to\n                   #  fills image.data_vectors and image.image_list  \n                   \nimage.calculate_tsne()  #  straight forward\n\nimage.create_image()  #  straight forward\n\n ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYontiLevin%2FEmbeddings2Image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FYontiLevin%2FEmbeddings2Image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FYontiLevin%2FEmbeddings2Image/lists"}