Tuesday 31 October 2017

Keras version error - how to know the version of keras - how to solve

model.add(LSTM(HIDDEN_LAYER_SIZE, dropout=0.2, recurrent_dropout=0.2))
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/models.py", line 475, in add
    output_tensor = layer(self.outputs[0])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/layers/recurrent.py", line 268, in __call__
    return super(Recurrent, self).__call__(inputs, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/topology.py", line 575, in __call__
    self.build(input_shapes[0])
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/layers/recurrent.py", line 1050, in build
    constraint=self.bias_constraint)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 87, in wrapper
    return func(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/topology.py", line 396, in add_weight
    weight = K.variable(initializer(shape),
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/layers/recurrent.py", line 1042, in bias_initializer
    self.bias_initializer((self.units * 2,), *args, **kwargs),
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 1709, in concatenate
    return tf.concat([to_dense(x) for x in tensors],axis)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/ops/array_ops.py", line 1075, in concat
    Returns:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 669, in convert_to_tensor
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 176, in _constant_tensor_conversion_function
    return constant(v, dtype=dtype, name=name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 165, in constant
    tensor_util.make_tensor_proto(value, dtype=dtype, shape=shape, verify_shape=verify_shape))
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 367, in make_tensor_proto
    _AssertCompatible(values, dtype)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 302, in _AssertCompatible
    (dtype.name, repr(mismatch), type(mismatch).__name__))
TypeError: Expected int32, got list containing Tensors of type '_Message' instead.





python3 -c 'import keras; print(keras.__version__)'


I only take tensorflow_backend.py in concatenate(tensors, axis)
Change this:
return tf.concat([to_dense(x) for x in tensors], axis)  
To this:
return tf.concat(axis,[to_dense(x) for x in tensors])

How to update tensorflo to a specific version or the latest

Specific Version
pip3 install 'tensorflow==1.0.0' --force-reinstall

Latest version
pip3 install tensorflow --upgrade 

Thursday 26 October 2017

./configure cudnn and cuda sdk

Please specify the CUDA SDK version you want to use, e.g. 7.0. [Leave empty to use system default]: 8.0

Please specify the location where CUDA 8.0 toolkit is installed. Refer to README.md for more details. [Default is /usr/local/cuda]: /Developer/NVIDIA/CUDA-8.0/

Please specify the cuDNN version you want to use. [Leave empty to use system default]: 7
Please specify the location where cuDNN 7 library is installed. Refer to README.md for more details. [Default is /Developer/NVIDIA/CUDA-8.0/]: /Users/zuni/cuda/lib
Please specify a list of comma-separated Cuda compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus.
Please note that each additional compute capability significantly increases your build time and binary size.

[Default is: "3.5,5.2"]: 5.0

how to check your added paths in mac


cat ~/.bash_profile

output:

# added by Miniconda2 4.3.21 instal/bin:$PATH"
export PATH=“/usr/local/bin:$PATH”/
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"
export PATH
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH

# added by Miniconda2 4.3.21 installer
export PATH="/Users/zuni/miniconda2/bin:$PATH"
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH

Wednesday 18 October 2017

how to start tensorboard

$pip install tensorflow-tensorboard

$which tensorboard

#if it shows then it is installed

$tensorboard --logdir '<location of your graph file till the folder not the file name>'

open http://localhost:6006/ on a web browser




how to make python3 default

alias python=python3
source ~/.bashrc
python --version

how to know the version of tensorflow - Mac - terminal

Type the below command in terminal

python3 -c 'import tensorflow as tf; print(tf.__version__)'

Wednesday 2 August 2017

config not found | Shakesphere - LSTM | init_py_ error

Error:


from app.views import net
  File "/Users/zuni/Documents/hbku/Research/shakespeare-LSTM-master/app/__init__.py", line 9, in <module>
    app.config.from_object('config')

  File "/Users/zuni/miniconda2/lib/python2.7/site-packages/flask/config.py", line 168, in from_object

.....

- missing __init__.py in a package;
- package or module path not included in sys.path;
- duplicated package or module name taking precedence in sys.path;
- missing module, class, function or variable;

Debugged import:

- 'config' not found.

Solution:

Thursday 6 July 2017

How to push a project to github from Android Studio

1. Create a repository on github in your account
2. Open mac terminal and go to the path where your repository is:
3. Type git branch
4. Choose the git branch that you want to move from your android studio and type the command below
      git push -u origin origine/master
5. Enter your git username when prompted
6. Enter your git password when prompted
7. Wait.... and it will be done.
8. Check on your github account under the repository name you chose.

Thursday 25 May 2017

Error: Default Activity Not Found

Whenever we run the android studio project on startup we get the the error running app: Default activity not found

This is resolved by doing this:

1. Go to AndroidManifest.xml file (press shift twice and enter the file name to search it in android studio)

2. Add this code:

<activity    android:name="com.your.package.name.YourActivity"    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

3. Go build.gradle add this code
sourceSets {
    main.java.srcDirs += 'src/main/<YOUR DIRECTORY>'}
Another easy way to solve the issue is:
When you import the android project use the steps below:
1. Download the git package using download zip
2. In android studio use Import from git
3. Direct to the directory where your project is saved and select the project folder
4. In the next step use import using manual gradle steps
5. Select empty Activity
6. Once it imports go to file>New>project
7. It will sync the project and make it an android project showing up gradle files in the 
   android select view.

Thursday 20 April 2017

plotly not the same for python/pycharm and the jupyter

Use this command below to install the plotly to work with jupyter

conda install -c https://conda.anaconda.org/plotly plotly

Thursday 30 March 2017

Cannot reiindex in python

all_data = pd.concat((train.loc[:,'MSSubClass':'SaleCondition'], test.loc[:,'MSSubClass':'SaleCondition']),ignore_index=True)

Just add ",ignore_index=True" at the end. This should solve the issue

Monday 27 March 2017

How to replace one column with the median values of the other column by grouping in python

X.loc[X.LotFrontage.isnull(), 'LotFrontage'] = X.groupby('Neighborhood').LotFrontage.transform('median')


X = the dataset name
LotFrontage = The column that has NA's
Neighborhood = The column that is to be used for grouping
median = can be replaced by mean etc...