<?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 Shaobo GUAN on Medium]]></title>
        <description><![CDATA[Stories by Shaobo GUAN on Medium]]></description>
        <link>https://medium.com/@summitkwan?source=rss-fe5c45c11bf4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*M2vf7axIWb35QyaoQgKpSw.png</url>
            <title>Stories by Shaobo GUAN on Medium</title>
            <link>https://medium.com/@summitkwan?source=rss-fe5c45c11bf4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 01:28:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@summitkwan/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[Generating custom photo-realistic faces using AI]]></title>
            <link>https://medium.com/insight-data/generating-custom-photo-realistic-faces-using-ai-d170b1b59255?source=rss-fe5c45c11bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d170b1b59255</guid>
            <category><![CDATA[creativity]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[insight-ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Shaobo GUAN]]></dc:creator>
            <pubDate>Thu, 25 Oct 2018 17:24:19 GMT</pubDate>
            <atom:updated>2018-10-26T21:21:30.915Z</atom:updated>
            <content:encoded><![CDATA[<h4>Controlled image synthesis and editing using a novel TL-GAN model</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*LZp9nkzbSk8v6cpwp8CD8g.gif" /><figcaption><em>Example video of the controlled synthesis using my model (transparent latent-space GAN, or TL-GAN)</em></figcaption></figure><p><strong><em>Want to learn applied Artificial Intelligence from top professionals in Silicon Valley or New York?</em></strong><em> </em>Learn more about the <a href="https://apply.insightdatascience.com/start?utm_source=tl-gan&amp;utm_medium=blog&amp;utm_content=top">Artificial Intelligence</a> program at Insight.</p><p><strong><em>Are you a company working in AI and would like to get involved in the Insight AI Fellows Program?</em></strong><em> Feel free to </em><a href="https://www.insightdatascience.com/partnerships?utm_source=tl-gan&amp;utm_medium=blog&amp;utm_content=top"><em>get in touch</em></a><em>.</em></p><p><em>All the code and online demo are available at the </em><a href="https://github.com/SummitKwan/transparent_latent_gan"><em>project page</em></a><em>.</em></p><h3>Teaching computers to draw photos according to descriptions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*lCAeDPpTkfvDqzZXiQoc1g.png" /><figcaption>Discriminative vs. generative tasks</figcaption></figure><p><em>Describing</em> an image is easy for humans, and we are able to do it from a very young age. In machine learning, this task is a <strong>discriminative </strong>classification/regression problem, i.e. predicting feature labels from input images. Recent advancements in ML/AI techniques, especially deep learning models, are beginning to excel in these tasks, sometimes reaching or exceeding human performance, as is demonstrated in scenarios like visual object recognition (e.g. from AlexNet to ResNet on ImageNet classification) and object detection/segmentation (e.g. from RCNN to YOLO on COCO dataset), etc.</p><p>However, the other way around, g<em>enerating</em> realistic images based on descriptions, is much harder, and takes years of graphic design training. In machine learning this is a <strong>generative</strong> task, which is also much more challenging than discriminative tasks, as a generative model has to produce much richer information (like a full image at some level of detail and variation) based on a smaller seed input.</p><p>Despite the difficulty in creating such types of applications, <strong>generative models</strong> (with some control) can be extremely useful in many cases:</p><ul><li><strong>Content creation</strong>: Imagine if an advertisement company could automatically generate attractive product images that match the content and style of the webpage where these images are inserted; a fashion designer could get inspiration by asking an algorithm to produce 20 examples of shoe designs that are related to “leisure”, “canvas”, “summer” and “passionate”; and a new game could allow players to create realistic avatars based simple descriptions.</li><li><strong>Content-aware smart editing</strong>: We could allow a photographer to change the facial expression, amount of wrinkles and hair style of a profile photo with several clicks; and a Hollywood studio artist could transform the footage shot on a cloudy evening to look like it was shot on a sunny morning, with sunshine shedding light from the left side of the screen.</li><li><strong>Data augmentation</strong>: An autonomous driving car company could synthesize realistic videos of a particular type of accident scenario to augment the training dataset; and a credit card company could synthesize data of a particular type of fraud data that is underrepresented in the dataset to improve their fraud detection system.</li></ul><p>In this post, we will describe our recent work called <strong>Transparent Latent-space GAN (TL-GAN)</strong>, which extends current cutting edge models to provide a new interface. We are currently working on a paper, that will have more technical details.</p><h3>Overview of generative models</h3><p>The deep learning community is making rapid progress on generative models. Among them are three promising types of models: <a href="https://arxiv.org/abs/1601.06759">autoregressive models</a>, <a href="https://arxiv.org/abs/1312.6114">variational autoencoders (VAE)</a> and <a href="https://arxiv.org/abs/1406.2661">generative adversarial networks (GAN)</a>, illustrated as the figure below. If you are interested in the details, please check out this awesome OpenAI blog <a href="https://blog.openai.com/generative-models/">post</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JFg3SRN0Uf-A7YWajQ6HOw.png" /><figcaption><em>Figure: comparison of generator networks. Image from </em><a href="https://wiki.math.uwaterloo.ca/statwiki/index.php?title=STAT946F17/Conditional_Image_Generation_with_PixelCNN_Decoders"><em>University of Waterloo STAT946F17 course</em></a></figcaption></figure><p>So far, GANs produce images of the <a href="https://blog.openai.com/generative-models/">highest quality</a> (photo-realistic and diverse, with convincing details in high resolution). Look at the stunning images generated by Nvidia’s recent work with pg-GAN (<a href="https://github.com/tkarras/progressive_growing_of_gans">progressively-growing GAN</a>). For this reason, this blog post will focus on GAN models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*F1HFYYfHgkjaEcGPrW5FDw.png" /><figcaption><em>Figure: synthetic images generated by </em><a href="https://github.com/tkarras/progressive_growing_of_gans"><em>pg-GAN</em></a><em> from Nvidia. None of these images are real!</em></figcaption></figure><h3>Controlling the output of GAN models</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*lzQ-xViUbiJSA0Ytu9YTQQ.png" /><figcaption>Figure: random image generation vs. controlled image generation</figcaption></figure><p>The <a href="https://arxiv.org/abs/1406.2661">original version of GAN</a> and many popular successors (like <a href="https://arxiv.org/abs/1511.06434">DC-GAN</a> and <a href="https://arxiv.org/abs/1710.10196">pg-GAN</a>) are <strong>unsupervised </strong>learning models. After training, the generator network takes random noise as input and produces a photo-realistic image that is barely distinguishable from the training dataset. However, we cannot further control the features of the generated images. In most applications (such as the scenarios described in the first section), users would like to generate samples with <strong>custom features</strong> (like age, hair color, facial expression, etc), and ideally, tuning each feature continuously.</p><p>To achieve controlled synthesis, numerous variants of GAN have been created. They can be roughly divided into two types: style-transfer networks and conditional generators.</p><h4>Style-transfer networks</h4><p>Style-transfer networks, represented by <a href="https://junyanz.github.io/CycleGAN/">CycleGAN</a> and <a href="https://phillipi.github.io/pix2pix/">pix2pix</a>, are models trained to translate image from one domain to another (e.g. from horse to zebra, from sketch to colored images). As a result, we cannot continuously tune one feature gradually between two discrete states (eg. add slightly more beard on the face). Also, one network is dedicated to one type of transfer, so it requires ten different neural networks to tune 10 features.</p><h4>Conditional generators</h4><p>Conditional generators, represented by <a href="https://arxiv.org/abs/1411.1784">conditional GAN</a>, <a href="https://arxiv.org/abs/1610.09585">AC-GAN</a>, and <a href="https://github.com/hanzhanggit/StackGAN">Stack-GAN</a>, are models that jointly learn images with feature labels during training time, enabling the image generation to be conditioned on custom features. Therefore, when you want to add new tunable features to the generation process, you have to retrain the whole GAN model, which takes an enormous amount of computing resources and time (e.g. days to weeks on a single K80 GPU with the perfect set of hyper-parameters). In addition, you have to rely on a single dataset that contains all the custom feature labels to perform the training, instead of leveraging different labels from multiple datasets.</p><p>Our model, which we call <strong>Transparent Latent-space GAN </strong>(TL-GAN), addresses these problems of existing methods by approaching controlled generation task from a novel angle. It offers users the ability to <strong>gradually tune one or multiple features using a single network</strong>. Besides, adding new tunable features can be done very efficiently in less than one hour.</p><h3>TL-GAN: a novel and efficient approach for controlled synthesis and editing</h3><h4>Making the mysterious latent space transparent</h4><p>We will leverage NVIDIA’s <a href="https://arxiv.org/abs/1710.10196">pg-GAN</a>, the model that generates the photo-realistic high resolution face images as shown in the the previous section. All the features of a generated 1024px*1024px image are determined solely by a 512-dimentional noise vector in the latent space (as a low-dimensional representation of the image content). Therefore, <strong>if we could understand what the latent space represents (i.e., making it transparent), we could completely control the generation process</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ChmB0i6NQGCpCyseOULISw.png" /><figcaption>Motivation of TL-GAN: understand latent space to control generation process</figcaption></figure><p>By experimenting with the pre-trained pg-GAN, I found that the latent space actually has two good properties:</p><ul><li>It is well populated, meaning that most points in the space will generate reasonable images</li><li>It is quite continuous, meaning the interpolation between two points in the latent space usually leads to a smooth transition of corresponding images.</li></ul><p>With this in mind, my intuition was that it is possible to find directions in the latent space that are predictive of features that we care about (eg. male-female). If so, we can use unit vectors of these directions as the feature axes for controlling the generation process (more male-like or more female-like).</p><h4>Approach: uncovering the feature axes</h4><p>To find these feature axes in the latent space, we will <strong>build a link between a latent vector <em>z</em> and the feature labels <em>y</em></strong> through supervised learning methods trained on paired <em>(z,y)</em> data. Now the problem becomes how to get such paired data, since existing datasets only contain images <em>x</em> and their corresponding feature labels <em>y</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*-VLgZiCEkwPROEtZaWxb4w.png" /><figcaption>Figure: approaches to link latent vector z with feature label y</figcaption></figure><p><strong>Potential approaches:</strong></p><blockquote>One potential approach is to compute the corresponding latent vectors <em>z</em> of images <em>x_real</em> from an existing dataset labeled with features of interest <em>y_real</em>. However, the GAN network does not offer an easy way to compute <em>z_encode=G^(−1)(x_real)</em>, making this idea difficult to implement.</blockquote><blockquote>A second potential approach is to generate synthetic images <em>x_gen</em> using GAN from a random latent vector <em>z</em> as <em>x_gen=G(z)</em>. The problem here is that the synthetic images are unlabeled, and we can not easily leverage the available labeled dataset.</blockquote><p>To solve this problem, the key innovation of our TL-GAN model is to <strong>train a separate feature extractor</strong> (a classifier for discrete label or regressor for continuous label) model <em>y=F(x)</em> using an existing labelled image dataset <em>(x_real, y_real)</em>, and then couple the trained GAN generator G with the feature extractor network F. Once this is done, we can predict the feature labels <em>y_pred</em> of the synthetic images <em>x_gen</em> using the trained feature extractor network, and thus establish the link between z and y through synthetic images as <em>x_gen=G(z)</em> and <em>y_pred=F(x_gen)</em>.</p><p>Now that we have the paired latent vector and features, we can train a regressor model <em>y=A(z)</em> to uncover all feature axes for controlling the image generation process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l6ug8cLOpd_TtxxgWlnw1Q.png" /><figcaption>Figure: architecture of our TL-GAN model</figcaption></figure><p>The above figure shows the architecture of the TL-GAN model, which contains five steps:</p><ol><li><strong>Learning the distribution:</strong> Choose a well-trained GAN model and take the generator network. I chose the well-trained pg-GAN (provided by Nvidia), which offers the best face generation quality.</li><li><strong>Classification:</strong> Choose a pre-trained feature extractor model (could be a convolutional neural network or other computer vision models), or train your own feature extractor network using a labelled dataset. I trained a simple convolutional neural network on the CelebA dataset (which contains 30,000+ face images with 40 labels each).</li><li><strong>Generation:</strong> Generate a number of random latent vectors, pass through the trained GAN generator to produce synthetic images, then use a trained feature extractor to produce features for every image.</li><li><strong>Correlation:</strong> Use a Generalized Linear Model (GLM) to perform regression between latent vectors and features. <strong>The regression slope becomes the feature axes.</strong></li><li><strong>Exploration:</strong> Start from one latent vector, move it along one or more feature axes, and examine how this affects the generated images.</li></ol><p>I made this process very efficient; once we have a pre-trained GAN model, identifying feature axes <strong>only takes one hour</strong> on a single-GPU machine. This is achieved by several engineering tricks including transfer learning, downsampling image size, pre-cache synthetic images, etc.</p><h3>Results</h3><p>Let us see how this simple idea works.</p><h4>Moving latent vector along feature axes</h4><p>First, I tested whether the discovered feature axes can be used to control the corresponding feature of the generated image. To do this, I generated a random vector <em>z_0</em> in the latent space of GAN, and produced a synthetic image <em>x_0</em> by passing it through the generator network <em>x_0=G(z_0)</em>. Next, I moved the latent vector along one feature axis <em>u</em> (a unit vector in the latent space, say, corresponding to the gender of the face) by distance <em>λ</em>, to a new location <em>x_1=x_0+λu</em>, and generated a new image <em>x1=G(z1)</em>. Ideally, the corresponding feature of the new image would be modified toward the expected direction.</p><p>The results of moving the latent space vector along several example feature axes (gender, age, etc) are shown below. This works surprisingly well! We can <strong>smoothly morph</strong> the image between male ←→ female, young←→old, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ow2h4j_v8jdnIJZzLcktlQ.png" /><figcaption>Figure: Initial result of moving latent vector along example entangled feature axes</figcaption></figure><h4>Disentangling correlated feature axes</h4><p>The examples above shows a shortcoming of the initial method, i.e., the <strong>entangled feature axes</strong>. For instance, when I intended to reduce the amount of beard, the generated faces became more female-like, which is not what a user would expect. This problem is due to the fact that the gender feature and the beard feature are by nature <strong>correlated</strong>, modifying one leading to the corollary change of the other. Similar things happened to other features like hairline and wavy hair. As is illustrated in the figure below, the original beard axis is not perpendicular to the gender axis in the latent space.</p><p>To solve this problem, I used straight-forward linear algebra tricks. Specifically, I projected the beard axis to a new direction that is orthogonal to the gender axis, which effectively removes their correlation, and thus could potentially disentangle these two features of generated face images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*0RPW3Rvqy_uDAoUpVzhfOA.png" /><figcaption>Figure: disentangle correlated feature axes using linear algebra tricks</figcaption></figure><p>I applied this feature disentangling method to the same example face. This time I used gender axis and age axis as reference features, projected all other feature axes so that they became orthogonal to gender and age, and examined the generated images when the latent vector moved along the newly generated feature axes (shown in the figure below). As we expected, the features including hairline, wavy hair and beard now modify the gender of face anymore, which behaves as expected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3OlC0FsszJlkL9uYDV5haQ.png" /><figcaption>Figure: Improved result of moving latent vector along example disentangled feature axes</figcaption></figure><h4>Flexible interactive editing</h4><p>To see how flexibly our TL-GAN model can control the image generation process, I built an interactive GUI to explore the effect of gradually tuning feature values along different feature axes, as shown below:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FO1by05eX424%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DO1by05eX424&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FO1by05eX424%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/89807e49d6a98a3d31699926a116a8c1/href">https://medium.com/media/89807e49d6a98a3d31699926a116a8c1/href</a></iframe><p>Again, the model works surprisingly well when I use the features axes to control the generated images!</p><h3>Recap</h3><p>This project provides a novel method to control the generation process of an unsupervised generative model like GAN (generative adversarial network). Using an already well-trained GAN generator (Nvidia’s pg-GAN), I made its latent space transparent by discovering the meaningful feature axes in it. When a vector moves along a feature axis in the latent space, the corresponding image morphs over this feature, which enables controllable synthesis and edit.</p><p>This method has clear advantages:</p><ol><li>Efficiency: To add a new feature tuner for the generator, you do not need to re-train the GAN model, thus it only takes &lt;1h to add 40 feature tuners with our method.</li><li>Flexibility: You can use any feature extractor trained on any dataset to add more feature tuners to the well-trained GAN.</li></ol><h4>A word about ethics</h4><p>This work allows us to have fine grained control over image generation, but it still relies heavily on the features of our dataset. Training on photos of celebrities of Hollywood means that our model will be very good at generating photos of a predominantly white and attractive demographic. In turn, this would lead to users only being able to generate these specific kind of faces which are only representative of a small subset of people. If we were to deploy this as an application, we would want to make sure that we have augmented our initial dataset to take into account the diversity of our users.</p><p>In addition, while this tool could be a huge creative help, we should ask ourselves how this model could be used for nefarious purposes. If we can generate realistic looking faces of any type, what are the implications for our ability to trust in what we see. These sort of issues are important to tackle today. As we have seen with the recent applications of <a href="https://en.wikipedia.org/wiki/Deepfake">deepfakes</a>, the capability of AI methods is increasing at a fast pace, so it is vital for us to start conversations about how to best deploy them.</p><h3>Online demo and code</h3><p>All the code and online demo of this work are available at <a href="https://github.com/SummitKwan/transparent_latent_gan">this Github project page</a>.</p><h4>If you want to play with the model in your web-browser</h4><p>You do not have to download any code, model or data. Just follow the instructions on <a href="https://github.com/SummitKwan/transparent_latent_gan#1-instructions-on-the-online-demo">this section</a> of the GitHub README page. You can tweak faces in your web-browser as is demonstrated in the the above Video.</p><h4>If you want to try my code</h4><p>Just follow the README page of the GitHub repository. The code is built on Anaconda Python 3.6 with Tensorflow and Keras.</p><h4>If you want to contribute</h4><p>You are very welcome! Feel free to submit a Pull Request or file an issue on Github</p><h4><strong>About me</strong></h4><p>I recently finished PhD in computational and cognitive neuroscience from Brown University, with a concurrent master degree in computer science focusing on machine learning. In the past, I studied how neurons in the brain collectively process information to achieve high-level functions like visual perception. I am enthusiastic about the algorithmic approach to understand, mimic, and implement intelligence, as well as apply them to solve challenging real-world problems. I am actively looking for ML/AI researcher positions in the tech industry.</p><h4>Acknowledgements</h4><p>This work was done as the project for the <a href="https://www.insightdata.ai/">Insight AI fellow program</a> over three weeks. I give my thanks to the program director <a href="https://twitter.com/EmmanuelAmeisen">Emmanuel Ameisen</a> and <a href="https://twitter.com/mrubash1">Matt Rubashkin</a> for their general guidance, especially <a href="https://twitter.com/EmmanuelAmeisen">Emmanuel Ameisen</a> for his suggestions and editing work on this blog post. I also give my thanks to all Insight staff for providing a great learning environment, and to Insight AI fellows from whom I learned a lot. Special thanks to <a href="https://www.linkedin.com/in/ruobing-xia/">Ruobing Xia</a> for providing numerous inspirations as I decided on project directions, and for the enormous help structuring and editing this blog post.</p><p>This passage was originally posted on my personal <a href="http://summit.metaneuro.com/index.php/2018/10/10/draw-as-you-can-tell-controlled-image-synthesis-an/">blog</a>.</p><p><strong><em>Want to learn applied Artificial Intelligence from top professionals in Silicon Valley or New York?</em></strong><em> </em>Learn more about the <a href="http://insightdata.ai/?utm_source=tl-gan&amp;utm_medium=blog&amp;utm_content=top">Artificial Intelligence</a> program at Insight.</p><p><strong><em>Are you a company working in AI and would like to get involved in the Insight AI Fellows Program?</em></strong><em> Feel free to </em><a href="https://www.insightdatascience.com/partnerships?utm_source=tl-gan&amp;utm_medium=blog&amp;utm_content=top"><em>get in touch</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d170b1b59255" width="1" height="1" alt=""><hr><p><a href="https://medium.com/insight-data/generating-custom-photo-realistic-faces-using-ai-d170b1b59255">Generating custom photo-realistic faces using AI</a> was originally published in <a href="https://medium.com/insight-data">Insight</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GUIDE: Work remotely on a Linux server from local Mac/Windows]]></title>
            <link>https://medium.com/@summitkwan/guide-work-remotely-on-a-linux-server-from-local-mac-windows-f05cdc6db0e0?source=rss-fe5c45c11bf4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f05cdc6db0e0</guid>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[nomachine]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[cyber]]></category>
            <dc:creator><![CDATA[Shaobo GUAN]]></dc:creator>
            <pubDate>Fri, 13 Jul 2018 19:31:13 GMT</pubDate>
            <atom:updated>2018-07-13T19:31:13.513Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<ul><li><a href="#toc_0">Summery:</a></li><li><a href="#toc_1">1. Terminal ssh</a></li><li><a href="#toc_2">1.1 Mac/Linux</a></li><li><a href="#toc_3">pure terminal, no GUI</a></li><li><a href="#toc_4">with GUI through XWindow forwarding</a></li><li><a href="#toc_5">file transfer</a></li><li><a href="#toc_6">1.2 MS Windows:</a></li><li><a href="#toc_7">1.3 Terminal Pros/Cons</a></li><li><a href="#toc_8">2. Terminal ssh with </a><a href="#toc_8">screen</a></li><li><a href="#toc_9">2.1 basics</a></li><li><a href="#toc_10">2.2 </a><a href="#toc_10">screen Pros/Cons</a></li><li><a href="#toc_11">3. GUI session via Xpra</a></li><li><a href="#toc_12">3.1. Xpra is screen for X11</a></li><li><a href="#toc_13">3.2 Xpra installation</a></li><li><a href="#toc_14">3.3 Basic Xpra usage</a></li><li><a href="#toc_15">3.3.1. start a session</a></li><li><a href="#toc_16">3.3.2 disconnect from a session:</a></li><li><a href="#toc_17">3.3.3 attach/return to a previous session</a></li><li><a href="#toc_18">3.3.4 check xpra sessions</a></li><li><a href="#toc_19">3.3.5 more details of xpra usage</a></li><li><a href="#toc_20">3.5 Xpra Pros/Cons</a></li><li><a href="#toc_21">4. NoMachine connection</a></li><li><a href="#toc_22">4.1 A better alternative to Xpra</a></li><li><a href="#toc_23">4.2 NoMachine installation</a></li><li><a href="#toc_24">4.3 full desktop forwarding</a></li><li><a href="#toc_25">4.4 application window forwarding</a></li><li><a href="#toc_26">4.4.1 start a session</a></li><li><a href="#toc_27">4.4.2 disconnect from a session</a></li><li><a href="#toc_28">4.4.2 attach to a existing session</a></li><li><a href="#toc_29">4.5 Keyboard shortcuts for Mac</a></li><li><a href="#toc_30">4.6 NoMachine Pros/Cons</a></li><li><a href="#toc_31">5. Conclusion</a></li></ul><p>Our lab has set up super powerful Linux server for data analysis (with multiple Xeon CPUs, multiple NVIDIA Tesla GPUs for cuda, and a lot of storage space. Being used to work on my own Macbook Pro, it did take me some time to figure out the best practice to work remotely.</p><p>Below I listed possible methods to connect to the server and the their pros and cons based on my experience.</p><h4>Summery:</h4><p>NoMachine works best, for NoMachine connection, jumps to section 4. For file sharing jump to 1.1</p><h4>1. Terminal ssh</h4><p>It requires the server to enable ssh, which most servers do.</p><h4>1.1 Mac/Linux</h4><h4>pure terminal, no GUI</h4><p>Open terminal, type</p><pre>ssh username@hostname</pre><p>hostname is the ip address or domain name and username is your account name on the server.</p><h4>with GUI through XWindow forwarding</h4><p>if you want to open GUI application from the remote server, just do:</p><pre>ssh -X username@hostname</pre><p>or</p><pre>ssh -Y username@hostname</pre><p>The -X or -Y option allows the XWindows of GUI apps to be forwarded to the local desktop</p><p>eg. bash xterm will open a term with gui, similarly, other applications like PyCharm, MatLab can pop-up a window and you can work the the interface as you are working locally.</p><p>Note: if the server is in an internal network (like university), you may need to first connect through VPN to ssh in.</p><h4>file transfer</h4><p>To transfer files between server and client, you could:</p><ul><li>ftp use tools like FileZilla (connect server through the sftp protocol, i.e. ftp via ssh), or</li><li>mount the remote directory in the naive file manager with the help of Mac Fusion</li></ul><ol><li>install Fuse for Mac</li><li>in terminal: sshfs username@hostname:/remote/directory/path /local/mount/point</li><li>the remote directory can be accessed using Finder</li></ol><h4>1.2 MS Windows:</h4><p>Windows does not come with a linux-like terminal, but there is a great application “MobaXterm”, which enables ssh connection and file transfer between server and client. Isn’t it awesome?</p><p>official website: <a href="https://mobaxterm.mobatek.net/">https://mobaxterm.mobatek.net</a></p><p>Similar with Mac/Linux, but more convenient, see simple demo at <a href="https://mobaxterm.mobatek.net/demo.html">https://mobaxterm.mobatek.net/demo.html</a></p><h4>1.3 Terminal Pros/Cons</h4><ul><li>Pros: convenient, minimal need to install software on server and client sides</li><li>Cons: <strong>LOST WORKING PROGRESS when connection is lost!</strong>, eg., 1) your session will be terminated and all the work will be lost when the network is not stable; 2) you can not continue to work on the same session by using another computer at home</li></ul><p>good for short-term connection for simple tasks</p><h4>2. Terminal ssh with screen</h4><h4>2.1 basics</h4><p>To keep the session alive despite lost connection, screen command is very helpful, but it only supports pure terminal applications, not GUI applications.</p><p>Basically, screen is a container, within in which other programs can run. the screen container persists even if the current terminal session gets interrupted. You can later attach to the &quot;screen&quot; from another computer to proceed your work</p><p>see:</p><ol><li>official documentation: <a href="https://www.gnu.org/software/screen/">https://www.gnu.org/software/screen/</a></li><li>quick guide <a href="https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/">https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/</a></li></ol><h4>2.2 screen Pros/Cons</h4><ul><li>Pros: current work survives over interrupted connection</li><li>Cons: terminal only, does not support GUI</li></ul><h4>3. GUI session via Xpra</h4><h4>3.1. Xpra is screen for X11</h4><p>We want a program like screen but supports GUI windows. After some search, I found xpra</p><p>xpra is, according to official site, a -</p><blockquote>multi-platform screen and application forwarding system “screen for X11”</blockquote><p>Another description of xpra, from Ubuntu documentation (<a href="https://help.ubuntu.com/community/Xpra">https://help.ubuntu.com/community/Xpra</a>):</p><blockquote>Xpra is a tool which allows you to run X programs — usually on a remote host — and then direct their display to your local machine, disconnect from these programs, and reconnect from the same or another machine, all without losing any state. It differs from standard X forwarding in that it allows disconnection and reconnection without disrupting the forwarded application; it differs from VNC and similar remote display technologies in that xpra is rootless: i.e., applications forwarded by xpra appear on your desktop as normal windows managed by your window manager, rather than being all “trapped in a box together”. Xpra also uses a custom protocol that is self-tuning and relatively latency- insensitive, and thus is usable over network connections that are too slow or unreliable for standard X forwarding.</blockquote><p>To use xpra, we have to install it on both the remote server and the local client.</p><h4>3.2 Xpra installation</h4><p>To use Xpra, we have to install it on both the remote server and the local client.</p><p>You can install through package manager like apt-get (eg. on Unbuntu, sudo apt-get install xpra) or by downloading and running installation files which can be found on the official site: <a href="https://xpra.org/trac/wiki/Download">https://xpra.org/trac/wiki/Download</a></p><h4>3.3 Basic Xpra usage</h4><p>I found the best way to use is:</p><h4>3.3.1. start a session</h4><p>from local client terminal:</p><p>local_client&gt; xpra start ssh/username@hostname/100 --start=xterm</p><ul><li>here 100 is a identifier of the session name, different user should use different identifiers and the same user an start multiple sessions by specifying distinct idendifiers, like 101, 5000, etc.</li><li>xterm is the GUI program to run on start, you can start any other GUI program from xterm</li></ul><h4>3.3.2 disconnect from a session:</h4><p>from local client terminal:</p><p>simply close the terminal in which the xpra session was running, or interrupt the current session by pressing ctrl+c. Or any unstable network will disconnect the local session</p><h4>3.3.3 attach/return to a previous session</h4><p>on local machine:</p><p>local_client&gt; xpra attach ssh/username@hostname/100</p><p>You can resume the previous session</p><h4>3.3.4 check xpra sessions</h4><p>if you want to list all the running sessions, just log into the remote server:</p><p>remote_server&gt; xpra list</p><p>if you want to terminate all sessions:</p><p>remote_server&gt; xpra stop</p><p>Note that this will terminate all your (but not other users’) xpra sessions and your work will be lost</p><p>if the font in your session is very small/large, this could be because mismatched DPI between server and client, you could try specifying --dpi when starting or attaching a session, like</p><p>local_client&gt; xpra attach ssh/username@hostname/100 --dip=96</p><h4>3.3.5 more details of xpra usage</h4><ul><li>see <a href="https://xpra.org/">https://xpra.org</a> for details</li><li>see <a href="http://manpages.ubuntu.com/manpages/xenial/man1/xpra.1.html">http://manpages.ubuntu.com/manpages/xenial/man1/xpra.1.html</a> for usage</li></ul><h4>3.5 Xpra Pros/Cons</h4><ul><li>Pros: enables GUI application to persists over disconnect/reconnect</li><li>Cons: not very stable, the session could crash (but you can reconnect and you will not lose your work), and the DPI problem and key-mapping problem can be annoying.</li></ul><h4>4. NoMachine connection</h4><h4>4.1 A better alternative to Xpra</h4><p>NoMachine, from my experience, is a better alternative of Xpra.</p><p>Like Xpra, it allows disconnecting and reconnecting without losing the work in the forwarded GUI application window or the full desktop, but it seems more stable and does not suffer from DPI mismatch or key-mapping problems. Also it provides a nice interface and you do not have to type in any commands for connections</p><p>see official site: <a href="https://www.nomachine.com/">https://www.nomachine.com</a></p><p>NoMachine uses X11 mechanism to display the remote GUI. On Mac, it is supported through the program <strong>XQuartz</strong>. You have to install it if it is not available on your machine.</p><p><a href="https://www.xquartz.org/">XQuartz</a></p><h4>4.2 NoMachine installation</h4><p>You have to install NoMachine on both remote server and local client. Simply follows the instructions</p><p><a href="https://www.nomachine.com/getting-started-with-nomachine">NoMachine - Getting started with NoMachine</a></p><p>If you have to install in command line: here is the instrctions:</p><p><a href="https://www.nomachine.com/AR01L00775">NoMachine - How to install NoMachine from the command line on Linux</a></p><h4>4.3 full desktop forwarding</h4><p>In local client machine, open NoMachine. Just follows the steps, connect using either NX or SSH protocols. start a desktop session</p><h4>4.4 application window forwarding</h4><h4>4.4.1 start a session</h4><p>In the local client machine, open NoMachine. Just follows the steps to establish a connection, (connect using either NX or SSH protocols). Then start a custom session</p><p>use floating window, and run xterm at start</p><p>Now you will see a GUI xterm popping up, and you can type in command and start any GUI program like matlab, charm, jupyter notebook, .etc. If you want to keep using the terminal after starting the application, add a &quot;&amp;&quot; after command, like matlab &amp;, the terminal will be still alive while you are using matlab</p><h4>4.4.2 disconnect from a session</h4><p>To disconnect, simply close the NoMachine window (not the application window), or in the NoMachine window -&gt; Connection -&gt; Disconnect</p><h4>4.4.2 attach to a existing session</h4><p>Open NoMachine, open the connection, and the previous session is shown there, double connect to connect back and resume the session.</p><p>To terminate the session, right click the session -&gt; terminate session (ongoing work in the session will be lost)</p><h4>4.5 Keyboard shortcuts for Mac</h4><p>When you are working on Mac, sometimes you want to map the command key as control key for the remote Linux machine, so that your familiar shortcuts on Mac would work on the linux system in most times. eg. cmd+C on your Mac is mapped as ctrl+C on the remote Linux. The easiest way to do that is to set the Xquatz default mapping file.</p><p>In terminal, create a file named .Xmodmap under your Mac home folder ~/, and put the commands in this file as below. This script will run automatically when the XQuartz starts, and applies only within XQuartz (with which NoMachine creates GUI).</p><p>reference:</p><p><a href="http://hints.macworld.com/article.php?story=20040425231058862">10.3: Get xmodmap to remap alt / option in X11 - Mac OS X Hints</a></p><h4>4.6 NoMachine Pros/Cons</h4><ul><li>Pros: GUI application persists over interrupted connection; more stable than Xpra, no DPI or keyboard mapping problem; convenient interface and no need to type in command</li><li>Cons: have not been found yet!</li></ul><p>Desktop forwarding vs application window forwarding:</p><ul><li>desktop forwarding: feel like working locally on the server, but more sluggist</li><li>application window forwarding: less sluggish, like running a local application. The Only option if the remote server is in terminal only mode (did not startx)</li></ul><h4>5. Conclusion</h4><p>After comparison, the NoMachine application window forwarding mode via NX protocol works best from my experience. You only have to install NoMachine on the server and client, and followed by several clicks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f05cdc6db0e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>