Skip to content

Instantly share code, notes, and snippets.

@wall72
Last active December 31, 2021 20:12
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wall72/e85a246a310d8129efa92a18fa266039 to your computer and use it in GitHub Desktop.
Save wall72/e85a246a310d8129efa92a18fa266039 to your computer and use it in GitHub Desktop.
install TensorFlow on Windows 10 Bash (include graphiclib)

install TensorFlow on Windows 10 Bash (include graphiclib)

1. install packages

sudo apt-get update
sudo apt-get install -y --no-install-recommends \
        build-essential \
        libfreetype6-dev \
        libpng12-dev \
        libzmq3-dev \
        pkg-config \
        python3-dev \
        python3-numpy \
        python3-pip \
        python3-scipy \
        python3-matplotlib \
        python3-pandas \
        python3-tk \
        unzip
sudo apt-get clean
sudo rm -rf /var/lib/apt/lists/*

2. install packages with pip

sudo pip3 install seaborn
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc2-cp34-cp34m-linux_x86_64.whl
sudo pip3 install --upgrade $TF_BINARY_URL
  • if install python3.5 and occur pip3 error
sudo pip3 install --upgrade pip
sudo pip3 install setuptools
sudo pip3 install seaborn
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc2-cp35-cp35m-linux_x86_64.whl
sudo pip3 install --upgrade $TF_BINARY_URL

3. edit .bashrc

  • adding environment variable DISPLAY
export DISPLAY=:0

4. install X-Server on Host

5. run test code

import numpy as np

num_puntos = 2000
conjunto_puntos = []
for i in range(num_puntos):
   if np.random.random() > 0.5:
     conjunto_puntos.append([np.random.normal(0.0, 0.9), np.random.normal(0.0, 0.9)])
   else:
     conjunto_puntos.append([np.random.normal(3.0, 0.5), np.random.normal(1.0, 0.5)])

import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns

df = pd.DataFrame({"x": [v[0] for v in conjunto_puntos],
        "y": [v[1] for v in conjunto_puntos]})
sns.lmplot("x", "y", data=df, fit_reg=False, size=6)
plt.show()

import tensorflow as tf

vectors = tf.constant(conjunto_puntos)
k = 4
centroides = tf.Variable(tf.slice(tf.random_shuffle(vectors),[0,0],[k,-1]))

expanded_vectors = tf.expand_dims(vectors, 0)
expanded_centroides = tf.expand_dims(centroides, 1)

assignments = tf.argmin(tf.reduce_sum(tf.square(tf.sub(expanded_vectors, expanded_centroides)), 2), 0)

means = tf.concat(0, [tf.reduce_mean(tf.gather(vectors, tf.reshape(tf.where( tf.equal(assignments, c)),[1,-1])), reduction_indices=[1]) for c in range(k)])

update_centroides = tf.assign(centroides, means)

init_op = tf.initialize_all_variables()

sess = tf.Session()
sess.run(init_op)

for step in range(100):
   _, centroid_values, assignment_values = sess.run([update_centroides, centroides, assignments])

data = {"x": [], "y": [], "cluster": []}

for i in range(len(assignment_values)):
  data["x"].append(conjunto_puntos[i][0])
  data["y"].append(conjunto_puntos[i][1])
  data["cluster"].append(assignment_values[i])

df = pd.DataFrame(data)
sns.lmplot("x", "y", data=df, fit_reg=False, size=6, hue="cluster", legend=False)
plt.show()
@achilleswu
Copy link

Seems the test is not working,

Traceback (most recent call last):
sns.lmplot("x", "y", data=df, fit_reg=False, size=6)
File "/usr/local/lib/python3.4/dist-packages/seaborn/regression.py", line 590, in lmplot
facets.map_dataframe(regplot, x, y, **regplot_kws)
File "/usr/local/lib/python3.4/dist-packages/seaborn/axisgrid.py", line 805, in map_dataframe
data_ijk = data_ijk.dropna()
File "/usr/lib/python3/dist-packages/pandas/core/frame.py", line 2411, in dropna
count = agg_obj.count(axis=agg_axis)
File "/usr/lib/python3/dist-packages/pandas/core/frame.py", line 3859, in count
counts = notnull(frame.values).sum(1)
File "/usr/lib/python3/dist-packages/pandas/core/common.py", line 276, in notnull
return -res
TypeError: The numpy boolean negative, the - operator, is not supported, use the ~ operator or the logical_not function instead.

@meron308
Copy link

am not able to download tensorflow using this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment