<?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 Wendy Mak on Medium]]></title>
        <description><![CDATA[Stories by Wendy Mak on Medium]]></description>
        <link>https://medium.com/@wendymak?source=rss-2147795cbd07------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*aQEExByRNV7bEKe6GiVBsQ.jpeg</url>
            <title>Stories by Wendy Mak on Medium</title>
            <link>https://medium.com/@wendymak?source=rss-2147795cbd07------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:24:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wendymak/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[Lessons learnt working with large datasets on postgres]]></title>
            <link>https://medium.com/@wendymak/lessons-learnt-working-with-large-datasets-on-postgres-5ae7f5552126?source=rss-2147795cbd07------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ae7f5552126</guid>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Wendy Mak]]></dc:creator>
            <pubDate>Sat, 06 Apr 2019 20:45:05 GMT</pubDate>
            <atom:updated>2019-04-06T20:45:05.663Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, I was working on a large-ish dataset on UK residential property sales, which I stored in a postgres database (around 3GB csv, 24million or so rows). It’s probably small in the ‘Big Data’ world, but manipulating it is definitely a lot harder than, say when you only have 20k or so rows. Also, I don’t have a very powerful computer for my database, so…</p><p>First problem: how do you count how many rows you have? A naive way might be to use:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e86bf13474fa713dd00b14948b54ef6c/href">https://medium.com/media/e86bf13474fa713dd00b14948b54ef6c/href</a></iframe><p>But if you are not prepared to wait (I gave up after a few minutes), there is a very handy approximate counting function from postgres wiki:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/041733b0c39dd296489f9c9c1697d1b9/href">https://medium.com/media/041733b0c39dd296489f9c9c1697d1b9/href</a></iframe><p>This returns in a second or so 👍. But the caveat being that if you have recently updated your table, and haven’t done a VACUUM it’s probably not what you are expecting. As per the <a href="https://www.postgresql.org/docs/current/catalog-pg-class.html">postgres docs</a>,</p><blockquote>This is only an estimate used by the planner. It is updated by VACUUM, ANALYZE, and a few DDL commands such as CREATE INDEX.</blockquote><p>For example, if you do:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54787d52efa76bc3388a31db8381d7c9/href">https://medium.com/media/54787d52efa76bc3388a31db8381d7c9/href</a></iframe><p>you’ll find that the reltuples trick will tell you that your table is empty, but in fact of course, it has the 24 million rows in it. Postgres planner just hasn’t quite caught up with your changes.</p><p>Second problem, how do you do an update that changes the data in certain columns in all the rows? For example, there are 3 columns that make up the full address, and I need to create a new column with them concatenated together. If you try to do UPDATE... SET... on 24 million rows you are going to be waiting a while… The trick is to recreate the table instead with the new column, which now runs a lot faster (at least 6 times speed up if not more)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af549a427def6477d7292f6f9764e5dc/href">https://medium.com/media/af549a427def6477d7292f6f9764e5dc/href</a></iframe><p>A bit of further digging into why these two tricks work point me towards the <a href="https://www.postgresql.org/docs/10/mvcc-intro.html">MVCC</a> model of postgres. From what I can understand, the database basically tries to make sure if 2 processes are working on the table (e.g. one updating rows, the other reading from the table), the reading process don’t have data changing underneath it, so postgres have to maintain a separate version, which makes the updates really slow if you have enough rows. (and as per the postgres wiki comment, the COUNT(*) is also slow since</p><blockquote><em>PostgreSQL has to check visibility for all rows</em></blockquote><p>Third thing to note is your indexes. They do have a tendency to slow down writes, so make sure you’ve removed them before doing a large bulk insert. (or conversely, if you need to do a query on the large dataset, make sure you’ve created the relevant index). Your indexes, together with their definition, can be found quite easily from the pg_indexes table using:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a4a467127a44b8e867a7fe5577515ce/href">https://medium.com/media/6a4a467127a44b8e867a7fe5577515ce/href</a></iframe><p>Hope you’ll find these tricks useful! (I certainly won’t forget them in a hurry… 😅)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ae7f5552126" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Google colab setup for working with kaggle (and datasets)]]></title>
            <link>https://medium.com/@wendymak/google-colab-setup-for-working-with-kaggle-and-datasets-c5d71eb2dad4?source=rss-2147795cbd07------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5d71eb2dad4</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[colab]]></category>
            <dc:creator><![CDATA[Wendy Mak]]></dc:creator>
            <pubDate>Sun, 31 Mar 2019 20:37:53 GMT</pubDate>
            <atom:updated>2019-03-31T20:39:36.197Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://colab.research.google.com/">Google colab</a> is great for data science, machine learning and deep learning experiments, especially as it got most of the useful packages installed, and you get the use of GPU for free (pretty much a must if your experiments uses neural networks).</p><p>If you also like to compete in Kaggle competitions (or just to play with their datasets), there’s also the option of using Kaggle kernels. However, I don’t always get on with them as their data directory is write only (some libraries by default require write access to this also), and also you can’t install extra packages without restarting the kernel. (no pip installed inside a cell allowed…) And it can be a bit annoying sometimes when the kernel crashes and you loose all your output…</p><p>Or sometimes you just want to use colab because you are doing some other stuff on there already.</p><p>My setup for colab goes as follows:</p><ul><li>setup a google cloud storage (gcs) bucket for stashing my models and intermediate data</li><li>save my kaggle keys (or other api keys you need) to another gcs bucket — this lets you use your keys securely without worrying having to upload them to the notebook everytime.</li><li>copy over the keys on startup (e.g. kaggle keys need to live in a .kaggle directory)</li><li>download any external datasets you need from the internet (this usually is a lot faster than on your home network 😉)</li><li>do some (hopefully cool) stuff with the data</li><li>copy over any important intermediate results and models to my gcp bucket</li></ul><p>So the colab setup goes as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/572af0736cb87c2b729c904f7925342f/href">https://medium.com/media/572af0736cb87c2b729c904f7925342f/href</a></iframe><p>For pulling data/models from gcs to collab workspace, the following is an example where I stored the KMNIST dataset (converted from np arrays to pngs) in a kmnist bucket, and copied it over to collab using gsutil cp .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18b4cd76b5f5cd4dbd09d79af315f66f/href">https://medium.com/media/18b4cd76b5f5cd4dbd09d79af315f66f/href</a></iframe><p>Copying up to gcs is just as easy with e.g.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a39d3283dcd713f0edb3adaaa8cb4bf/href">https://medium.com/media/6a39d3283dcd713f0edb3adaaa8cb4bf/href</a></iframe><p>More options for working with external datasets can be found at <a href="https://colab.research.google.com/notebooks/io.ipynb">https://colab.research.google.com/notebooks/io.ipynb</a></p><p>So there it is, a simple setup for colab + kaggle (+ fastai).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5d71eb2dad4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[stopping ssh connection to AWS ec2 from timing out]]></title>
            <link>https://medium.com/@wendymak/stopping-ssh-connection-to-aws-ec2-from-timing-out-4beb1e5ffb85?source=rss-2147795cbd07------2</link>
            <guid isPermaLink="false">https://medium.com/p/4beb1e5ffb85</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[ssh]]></category>
            <dc:creator><![CDATA[Wendy Mak]]></dc:creator>
            <pubDate>Thu, 16 Aug 2018 19:45:02 GMT</pubDate>
            <atom:updated>2018-08-16T19:45:02.204Z</atom:updated>
            <content:encoded><![CDATA[<ol><li>go to /etc/ssh on your system</li><li>open ssh_config file with sudo nano ssh_config</li><li>add ServerAliveInterval 60 to the file</li><li>restart sshd service with (on macos):</li></ol><pre>sudo launchctl stop com.openssh.sshd<br>sudo launchctl start com.openssh.sshd</pre><p>Hat tip to https://www.quora.com/Why-does-ssh-to-amazon-ec2-instance-gets-frozen-after-sometime and http://vivo.pub/2409</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4beb1e5ffb85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tflite for raspberry pi]]></title>
            <link>https://medium.com/@wendymak/tflite-for-raspberry-pi-c5cedf7cae2?source=rss-2147795cbd07------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5cedf7cae2</guid>
            <category><![CDATA[raspberry-pi]]></category>
            <category><![CDATA[tensorflow-lite]]></category>
            <dc:creator><![CDATA[Wendy Mak]]></dc:creator>
            <pubDate>Sat, 28 Jul 2018 20:34:11 GMT</pubDate>
            <atom:updated>2018-07-29T21:17:15.948Z</atom:updated>
            <content:encoded><![CDATA[<p>I am trying to setup an object detector on my raspberry pi, and with the recent tflite release, I am hoping to have something ‘lite’ running nicely. However, I found the docs a bit patchy as to what exactly I have to do, so after a lot of digging, here’s what I found/did.</p><p>Install tensorflow on the pi as per <a href="https://www.tensorflow.org/install/install_raspbian">https://www.tensorflow.org/install/install_raspbian</a></p><ol><li>sudo apt install libatlas-base-dev</li><li>pip3 install tensorflow .</li></ol><p>On your main computer:</p><ol><li>install bazel (for me, I am using a mac, so brew install bazel did the trick).</li><li>clone the tensorflow repo at <a href="https://github.com/tensorflow/tensorflow">https://github.com/tensorflow/tensorflow</a></li><li>download the mobilenet ssd frozen graph (pick the one you need from <a href="https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md">https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/detection_model_zoo.md</a>)</li><li>clone the TF models repo (<a href="https://github.com/tensorflow/models/tree/master/research">https://github.com/tensorflow/models</a>) and run an install inside the models directory:<br>python setup.py build <br>python setup.py install</li><li>Make sure you have installed all the extra requirements, especially the protobuf as per <a href="https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md">https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md</a></li><li>** remember to compile the protobuf <br># From tensorflow/models/research/<br>protoc object_detection/protos/*.proto — python_out=.</li><li>Inside the research folder, run (the add_postprocessing_op option means that the output will have the bounding boxes etc separated out):</li></ol><pre>python object_detection/export_tflite_ssd_graph.py <br>—-pipeline_config_path=/{path_to_mobilenet_model_file}/pipeline.config--trained_checkpoint_prefix=/{path_to_mobilenet_model_file}/model.ckpt —-output_directory=/{path_to_mobilenet_model_file}/ <br>--add_postprocessing_op=true</pre><p>8. Inside the tensorflow folder you have cloned, run (note, when you first run bazel for the first time I think it has to do some sort of compilation so it takes a while, after that it converts fairly quickly). Also, what params to pass in to inference_type depends on your model, it’s different if it’s not a float model</p><pre>bazel run -c opt tensorflow/contrib/lite/toco:toco -- \<br>--input_file=/{path_to_mobilenet_model_file}/tflite_graph.pb \<br>--output_file=/{path_to_mobilenet_model_file}/detect.tflite \<br>--input_shapes=1,300,300,3 \<br>--input_arrays=normalized_input_image_tensor \<br>--output_arrays=&#39;TFLite_Detection_PostProcess&#39;,&#39;TFLite_Detection_PostProcess:1&#39;,&#39;TFLite_Detection_PostProcess:2&#39;,&#39;TFLite_Detection_PostProcess:3&#39; \<br>--inference_type=FLOAT \<br>--allow_custom_ops</pre><p>9. This should result in a detect.tflite file in path_to_mobilenet_model_file directory that you can now use.</p><p>Most of it is from the ‘official’ documentation at <a href="https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_on_mobile_tensorflowlite.md">https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_on_mobile_tensorflowlite.md</a> , with some stackoverflow +googling of various errors I got. Putting it here so I don’t forget next time I have to do it!</p><p>now on to seeing if I can get it to run on my pi… (now on to looking at what <a href="https://github.com/freedomtan/tensorflow/blob/deeplab_tflite_python/tensorflow/contrib/lite/examples/python/object_detection.py">https://github.com/freedomtan/tensorflow/blob/deeplab_tflite_python/tensorflow/contrib/lite/examples/python/object_detection.py</a> did and how I can get it to work with my pi camera+video…)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5cedf7cae2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sending commands to multiple iTerm tabs]]></title>
            <link>https://medium.com/@wendymak/sending-commands-to-multiple-iterm-tabs-f18b66dc5387?source=rss-2147795cbd07------2</link>
            <guid isPermaLink="false">https://medium.com/p/f18b66dc5387</guid>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[shortcuts]]></category>
            <dc:creator><![CDATA[Wendy Mak]]></dc:creator>
            <pubDate>Thu, 06 Jul 2017 20:34:55 GMT</pubDate>
            <atom:updated>2017-07-06T20:36:46.833Z</atom:updated>
            <content:encoded><![CDATA[<p>My terminal setup of choice is iTerm2 with <a href="https://github.com/robbyrussell/oh-my-zsh">Oh-my-zsh</a> . And there’s a handy shortcut to send commands to all the open tabs in a window simultaneously (e.g. if you want to cd into the same directory on multiple tabs, or run the same script…)</p><p>On a mac, this is `cmd + shift + I`</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EX5MSO8AIiqqjvc6aNY8zw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f18b66dc5387" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>