<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shiyu Chen on Medium]]></title>
        <description><![CDATA[Stories by Shiyu Chen on Medium]]></description>
        <link>https://medium.com/@shiyuchen_83715?source=rss-2aef77498708------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Q5b48OwqP_-jFylg_m5OnA.png</url>
            <title>Stories by Shiyu Chen on Medium</title>
            <link>https://medium.com/@shiyuchen_83715?source=rss-2aef77498708------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 23:27:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shiyuchen_83715/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to push large files with git-lfs]]></title>
            <link>https://towardsdev.com/how-to-push-large-files-with-git-lfs-9f7b81a926fe?source=rss-2aef77498708------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f7b81a926fe</guid>
            <category><![CDATA[git-lfs]]></category>
            <category><![CDATA[fl]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[towhee]]></category>
            <dc:creator><![CDATA[Shiyu Chen]]></dc:creator>
            <pubDate>Mon, 28 Feb 2022 08:18:12 GMT</pubDate>
            <atom:updated>2022-03-01T12:28:24.808Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZteKyxz7tWrFhyAxwBpl5g.jpeg" /></figure><h3>What is Git LFS</h3><p>Git LFS (Large File Storage) can store any specified file outside the Git repository, and use pointers instead in the Git repository. By storing large files outside the Git repository, you can reduce the size of the Git repository itself, speed up the cloning of the Git repository, and prevent Git from affecting performance or even cloning failure because the repository is full of large files.</p><h3>Installation</h3><p>Refer to <a href="https://git-lfs.github.com/">Git LFS</a>, <em>note that required Git &gt;= 1.8.2</em></p><pre># on <em>Mac</em></pre><pre>$ brew install git-lfs</pre><pre>$ git lfs install</pre><h3>How to use</h3><p>Git LFS uses <a href="https://git-scm.com/docs/gitattributes">gitattributes</a> to declare and add large files, which is a git mechanism that binds special behaviors to certain file patterns. Git LFS binds to filters using tracked file patterns via the <strong>.gitattributes</strong> file.</p><h3>Add large file</h3><p>Large files can be added manually or tracked via the command line.</p><p><strong>1) Add file manually</strong></p><p>Create <strong>.gitattributes</strong> file with vim .gitattributes to add the file format of the large file. Such as &quot;.gz&quot; files, you need to add the following text to .<strong>gitattributes</strong>:</p><pre>*.gz filter=lfs diff=lfs merge=lfs -text</pre><p><strong>2) Add file with command</strong></p><ol><li>View the existing large file track</li></ol><pre>$ git lfs track</pre><p>2. Add the file format of the large file, such as “.gz” file:</p><pre>$ git lfs track *.gz</pre><p>After tracking the type, check the file <strong>.gitattributes</strong>, you can see a new line in <strong>.gitattributes</strong>: <em>*.gz filter=lfs diff=lfs merge=lfs -text</em></p><h3>Check files</h3><p>Then you can list all the large files with git-lfs.</p><pre>$ git lfs ls-files</pre><h3>Push file</h3><p>The command to push large files to the git repository is the same as <a href="https://git-scm.com/">git</a> commands.</p><blockquote><em>Note that the </em><strong><em>.gitattributes</em></strong><em> file needs to be saved in the root directory of the repo, so that it will work when cloned.</em></blockquote><pre>$ git add .gitattributes</pre><pre>$ git add my.gz</pre><pre>$ git commit -m &quot;add gz file&quot;</pre><pre>$ git push</pre><ul><li>After pushing to the remote repository, the files tracked by LFS will be displayed in the form of “Git LFS” <a href="https://towhee.io/towhee/torch-vggish/src/branch/main/pytorch/vggish.pth">in towhee hub</a>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*KOLglrImwub7OQhuSrnpyA.png" /></figure><ul><li>Use git clone when using.</li><li>Get help for Git LFS: git lfs help.</li></ul><h3>Examples</h3><pre>To get started with Git LFS, the following commands can be used.</pre><pre>1. Setup Git LFS on your system. You only have to do this once per repository per machine:</pre><pre>       git lfs install</pre><pre>2. Choose the type of files you want to track, for examples all ISO</pre><pre>images, with git lfs track:</pre><pre>       git lfs track &quot;*.iso&quot;</pre><pre>3. The above stores this information in gitattributes(5) files, so that file need to be added to the repository:</pre><pre>       git add .gitattributes</pre><pre>4. Commit, push and work with the files normally:</pre><pre>       git add file.iso<br>       git commit -m &quot;Add disk image&quot;<br>       git push</pre><p>Thanks to git-lfs, <a href="https://towhee.io/">towhee hub</a> can be very friendly to manage large files, such as models, datasets, etc. As an open-source machine learning framework, you are also very welcome to contribute your own models to <a href="https://github.com/towhee-io/towhee">Towhee</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f7b81a926fe" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/how-to-push-large-files-with-git-lfs-9f7b81a926fe">How to push large files with git-lfs</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Combine AI Models for Image Search using ONNX and Milvus]]></title>
            <link>https://medium.com/@shiyuchen_83715/combine-ai-models-for-image-search-using-onnx-and-milvus-5d56c24376ad?source=rss-2aef77498708------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d56c24376ad</guid>
            <dc:creator><![CDATA[Shiyu Chen]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 02:22:37 GMT</pubDate>
            <atom:updated>2021-09-30T02:28:38.528Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SMu2MYFhaf7p4nKg" /></figure><p>Open Neural Network Exchange (ONNX) is an open format built to represent machine learning models. Since it was open-sourced in 2017, ONNX has developed into a standard for AI, providing building blocks for machine learning and deep learning models. ONNX defines a common file format to enable AI developers to use models with various frameworks, tools, runtimes, and compilers, and helps increase the speed of innovation in the artificial intelligence community.</p><p>Milvus is an open-source vector database that is highly flexible, reliable and blazing fast. It supports adding, deleting, updating and near real-time search of vector. Milvus has a comprehensive set of intuitive APIs, and support for multiple widely adopted index libraries (e.g. Faiss, NMSLIB, and Annoy), simplifying the index selection for a given scenario. Milvus is simple to use, and it has been used in hundreds of organizations and institutions worldwide, including image, audio and video search, recommendation, chatbot, new drug search, etc.</p><p>This article will introduce you how to use multiple models for image search based on ONNX and Milvus. It takes VGG16 and ResNet50 models as examples, uses ONNX to run different AI models to generate feature vectors, and finally performs feature vector retrieval in Milvus to return similar images. There is an open sourced Jupyter Notebook code file for this project on <a href="https://github.com/milvus-io/bootcamp/blob/master/etc/onnx_and_milvus/milvus_with_different_models.ipynb">GitHub</a>, and next we will show you how to achieve.</p><h3>Process Models with ONNX</h3><p>The ONNX format can be easily exchanged between AI models. For example, the TensorFlow model can be converted to ONNX format and run in the Caffe environment. In this example, we convert the pre-trained ResNet50 model under the Keras framework to the ONNX format, and then call the VGG16 model in ONNX format to analyze different models.</p><pre>from keras.applications.resnet50 import ResNet50<br>import tensorflow as tf<br>​<br># load keras-resnet50 model and save as a floder<br>model_resnet50 = ResNet50(include_top=False, pooling=&#39;max&#39;, weights=&#39;imagenet&#39;)<br>tf.saved_model.save(model_resnet50, &quot;keras_resnet50_model&quot;)<br>​<br># convert resnet50 model to onnx<br>! python -m tf2onnx.convert --saved-model &quot;keras_resnet50_model&quot; --output &quot;onnx_resnet50.onnx&quot;</pre><p>Note: When we used the interface keras2onnx.convert_keras(model, model.name) to convert the model, it will return the error AttributeError:&#39;KerasTensor&#39; object has no attribute&#39;graph&#39;. Then we can use Python&#39;s Bash command to convert according to the solution on Stack Overflow.</p><h3>Extract Feature Vectors using Models</h3><p>After converting ResNet50 model into ONNX format, you can extract the feature vector of the picture directly through the inference. Note: Feature vectors need to be normalized after extraction.</p><pre># get the image vectors with onnx model<br>def get_onnx_vectors(onnx_model, img_path):<br>    img = image.load_img(img_path, target_size=(224, 224))<br>    x = image.img_to_array(img)<br>    x = np.expand_dims(x, axis=0)<br>    x = preprocess_input(x)<br>    <br>    sess = onnxruntime.InferenceSession(onnx_model)<br>    x = x if isinstance(x, list) else [x]<br>    feed = dict([(input.name, x[n]) for n, input in enumerate(sess.get_inputs())])<br>    feat = sess.run(None, feed)[0]<br>    <br>    norm_feat = feat[0] / LA.norm(feat[0])<br>    norm_feat = [i.item() for i in norm_feat]<br>    return norm_feat</pre><p>Use ONNX-formatted VGG16 model to process image data:</p><pre># generate vectors with ResNet50 and VGG16 ONNX model<br>vec_resnet = get_onnx_vectors(&quot;onnx_resnet50.onnx&quot;, &quot;./pic/example.jpg&quot;)<br>vec_vgg = get_onnx_vectors(&quot;onnx_vgg16.onnx&quot;, &quot;./pic/example.jpg&quot;)</pre><h3>Store Vector Data</h3><p>Unstructured data such as pictures cannot be directly processed by computer, but it can be converted into vectors through AI model and then analyzed by a computer. Milvus vector database is designed power massive unstructured data analysis. It can store vector data and perform near real-time analysis. First, create a collection of the corresponding model in Milvus, and then insert the image vectors.</p><pre>from milvus import *<br>​<br># create collections in Milvus<br>milvus.create_collection(resnet_collection_param)<br>milvus.create_collection(vgg_collection_param)<br>​<br># insert data to Milvus and return ids<br>status, resnet_ids = milvus.insert(resnet_collection_name, resnet_vectors)<br>status, vgg_ids = milvus.insert(vgg_collection_name, vgg_vectors)</pre><p>After inserting the data successfully, Milvus will return the ID corresponding to the vector, and then we can find the picture by ID. Since Milvus 1.1 used in this case does not support scalar filtering (which Milvus 2.0 now supports), Redis is used to store the vector ID and the key-value of the image path.</p><pre>import redis<br>def img_ids_to_redis(img_directory, res_ids):<br>  for img, ids in zip(images, res_ids):<br>    redis.set(ids, img)</pre><h3>Search for Similar Images</h3><p>After storing the data, we can retrieve the vector. Milvus supports multiple distance calculation methods, including Euclidean, inner product and Hamming distance. The image similarity search in this article adopts the Euclidean distance calculation between the vectors in Milvus, returns the similar vector ID, and then finds the image corresponding to the ID in Redis.</p><pre># search in Milvus and return the similarly results with ids<br>def search_in_milvus(collection_name, search_vector):<br>    status, results = milvus.search(collection_name, TOP_K, [search_vector])<br>    print(status)<br>    re_ids = [x.id for x in results[0]]<br>    re_distance = [x.distance for x in results[0]]<br>    return re_ids, re_distance<br>    <br># get the images according the result ids<br>def get_sim_imgs(collection_name, search_vector):<br>    ids, distance = search_in_milvus(collection_name, search_vector)<br>    img = [red.get(i).decode(&quot;utf-8&quot;) for i in ids]<br>    return ids, distance, img</pre><p>Taking the VGG16 and ResNet50 models as examples, this article shows processing multiple models through ONNX and combining multiple models with Milvus for similar vector retrieval to get similar images. The above two models are based on the Keras framework, which can quickly extract feature vectors. It can be seen from the Notebook that although the results of Milvus&#39;s search for pictures on the COCO dataset based on these two models are similar, their Euclidean distances are not the same. You can also try to compare the search results of the two models using other datasets.</p><p>Milvus is a high-performance, highly available vector database that can be used to process feature vectors generated from massive unstructured data. For more solutions, you can refer to <a href="https://github.com/milvus-io/bootcamp">Milvus bootcamp</a>.</p><h3>References</h3><ol><li><a href="https://github.com/onnx/onnx">https://github.com/onnx/onnx</a></li><li><a href="https://onnx.ai/">https://onnx.ai/</a></li><li><a href="https://milvus.io/cn/">https://milvus.io/cn/</a></li><li><a href="https://github.com/milvus-io/bootcamp">https://github.com/milvus-io/bootcamp</a></li></ol><h3>About author</h3><p>Shiyu Chen, a data engineer at Zilliz, graduated from Xidian University with a degree in Computer Science. Since joining Zilliz, she has been exploring solutions for Milvus in various fields, such as audio and video analysis, molecule formula retrieval, etc., which has greatly enriched the application scenarios of the community. She is currently exploring more interesting solutions. In her spare time, she loves sports and reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d56c24376ad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>