mxnet sagemaker load model - amazon-web-services

I'm trying to load an already trained model from sagemaker MXnet.
I have the model.tar.gz file, however, when I try to do
> %%bash
> tar -xzf model.tar.gz rm model.tar.gz
> prefix = 'model_name'
> sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, 0)
> mod = mx.mod.Module(symbol=sym,
> context=ctx, label_names=None) mod.bind(for_training=False, data_shapes=[('data', (1,3,480,480))], label_shapes=mod._label_shapes)
> mod.set_params(arg_params, aux_params)
I keep getting the error Error in operator multibox_target: [09:08:47] src/operator/contrib/./multibox_target-inl.h:225: Check failed: lshape.ndim() == 3 (0 vs. 3) Label should be [batch-num_labels-(>=5)] tensor
Can anyone help me with this?

I believe you have to run deploy.py prior to being able to prediction.
check out incubator-mxnet\example\ssd\deploy.py
and note the model files need to be in a subdirectory of the directory where deploy.py is located.
this worked for my resnet50 based model.
python deploy.py --network resnet50 --prefix model2/model_algo_1 --num-class 2 --data-shape 416

Thank you #lwebuser suggestion. I wrote an end-to-end example at the jupyter notebook. Here is the link
You can see the result:

Related

Nix Gradle dist - Failed to load native library 'libnative-platform.so' for Linux amd64

I am trying to build a Freeplane derivation based on Freemind, see: https://github.com/razvan-panda/nixpkgs/blob/freeplane/pkgs/applications/misc/freeplane/default.nix
{ stdenv, fetchurl, jdk, jre, gradle }:
stdenv.mkDerivation rec {
name = "freeplane-${version}";
version = "1.6.13";
src = fetchurl {
url = "mirror://sourceforge/project/freeplane/freeplane%20stable/freeplane_src-${version}.tar.gz";
sha256 = "0aabn6lqh2fdgdnfjg3j1rjq0bn4d1947l6ar2fycpj3jy9g3ccp";
};
buildInputs = [ jdk gradle ];
buildPhase = "gradle dist";
installPhase = ''
mkdir -p $out/{bin,nix-support}
cp -r ../bin/dist $out/nix-support
sed -i 's/which/type -p/' $out/nix-support/dist/freeplane.sh
cat >$out/bin/freeplane <<EOF
#! /bin/sh
JAVA_HOME=${jre} $out/nix-support/dist/freeplane.sh
EOF
chmod +x $out/{bin/freeplane,nix-support/dist/freeplane.sh}
'';
meta = with stdenv.lib; {
description = "Mind-mapping software";
homepage = https://www.freeplane.org/wiki/index.php/Home;
license = licenses.gpl2Plus;
platforms = platforms.linux;
};
}
During the gradle build step it is throwing the following error:
building path(s)
‘/nix/store/9dc1x2aya5p8xj4lq9jl0xjnf08n7g6l-freeplane-1.6.13’
unpacking sources unpacking source archive
/nix/store/c0j5hgpfs0agh3xdnpx4qjy82aqkiidv-freeplane_src-1.6.13.tar.gz
source root is freeplane-1.6.13 setting SOURCE_DATE_EPOCH to timestamp
1517769626 of file freeplane-1.6.13/gitinfo.txt patching sources
configuring no configure script, doing nothing building
FAILURE: Build failed with an exception.
What went wrong: Failed to load native library 'libnative-platform.so' for Linux amd64.
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. builder for ‘/nix/store/id4vfk3r6fd4zpyb15dq9xfghf342qaa-freeplane-1.6.13.drv’
failed with exit code 1 error: build of
‘/nix/store/id4vfk3r6fd4zpyb15dq9xfghf342qaa-freeplane-1.6.13.drv’
failed
Running gradle dist from terminal works fine. I'm guessing that maybe one of the globally installed Nix packages provides a fix to the issue and they are not visible during the build.
I searched a lot but couldn't find any working solution. For example, removing the ~/.gradle folders didn't help.
Update
To reproduce the issue just git clone https://github.com/razvan-panda/nixpkgs, checkout the freeplane branch and run nix-build -A freeplane in the root of the repository.
Link to GitHub issue
Maybe you just don't have permission for the folder/file
sudo chmod 777 yourFolderPath
you can also : sudo chmod 777 yourFolderPath/* (All folder)
Folder will not be locked,then You can use it normally
[At least I succeeded。。。]
EX:
sudo chmod 777 Ruby/
now ,that's ok
To fix this error: What went wrong: Failed to load native library 'libnative-platform.so' for Linux amd64. do the following:
Check if your Gradle cache (**~user/.gradle/**native folder exist at all or not).
Check if your Gradle cache (~user/.gradle/native folder exist and the file in question i.e. libnative-platform.so exists in that directory or not).
Check if the above folder ~user/.gradle or ~/.gradle/native or file: ~/.gradle/native/libnative-platform.so has valid permissions (should not be read-only. Running chmod -R 755 ~/.gradle is enough).
IF you don't see native folder at all or if your native folder seems corrupted, run your Gradle task ex: gradle clean build using -g or --gradle-user-home option and pass it's value.
Ex: If I ran mkdir /tmp/newG_H_Folder; gradle clean build -g /tmp/newG_H_Folder, you'll see Gradle will populate all the required folder/files (that it needs to run even before running any task or any option) are now in this new Gradle Home folder (i.e. /tmp/newG_H_Folder/.gradle directory).
From this folder, you can copy - just the native folder to your user's ~/.gradle folder (take backup of existing native folder in ~/.gradle first if you want to) if it already exists -or copy the whole .gradle folder to your ~ (home directory).
Then rerun your Gradle task and it won't error out anymore.
Gradle docs says:
https://docs.gradle.org/current/userguide/command_line_interface.html
-g, --gradle-user-home
Specifies the Gradle user home directory. The default is the .gradle directory in the user’s home directory.

Error:- tensorboard: command not found . However, while typing locate tensorboard, I am getting the the location

I am a beginner in tensorflow. I ran a simple script as below :
import tensorflow as tf
a =tf.constant(2)
b = tf.constant(3)
c = tf.add(a,b)
with tf.Session() as sess:
writer = tf.summary.FileWriter('./graphs',sess.graph)
print sess.run(c)
writer.close()
After saving this python file, I ran it in terminal. There is folder graphs created with 2 events file. Then I ran following command on terminal :
tensorboard --logdir="./graphs"
I am getting following error:
tensorboard: command not found
Please help. Thanks in advance.
​
As you mentioned you are getting tensorboard location, try to run your command with your local path, ex
/your/path/tensorboard --logdir="./graphs"
Hope this will help you, happy coding

aws devicefarm python upload apk - android_app_aapt_debug_badging_failed

I am uploading the APK using python code, when I check for status after create_upload and uploading the actual file then I keep getting FAILED with android_app_aapt_debug_badging_failed. Any Idea why ?
Sorry to hear that you are running into issues with the upload.
For the error code you are facing, i am pasting the debugging steps below
Debugging Steps
During the upload validation process, AWS Device Farm parses out information from the output of an "aapt debug badging " command.
Make sure that you can run this command on your Android application successfully. In the following example, the package's name is app-debug.apk.
Copy your application package to your working directory, and then run the command:
$ aapt debug badging app-debug.apk
A valid Android application package should produce output like the following:
package: name='com.amazon.aws.adf.android.referenceapp' versionCode='1' versionName='1.0' platformBuildVersionName='5.1.1-1819727'
sdkVersion:'9'
application-label:'ReferenceApp'
application: label='ReferenceApp' icon='res/mipmap-mdpi-v4/ic_launcher.png'
application-debuggable
launchable-activity: name='com.amazon.aws.adf.android.referenceapp.Activities.MainActivity' label='ReferenceApp' icon=''
uses-feature: name='android.hardware.bluetooth'
uses-implied-feature: name='android.hardware.bluetooth' reason='requested android.permission.BLUETOOTH permission, and targetSdkVersion > 4'
main
supports-screens: 'small' 'normal' 'large' 'xlarge'
supports-any-density: 'true'
locales: '--_--'
densities: '160' '213' '240' '320' '480' '640'
I was having this exact issue, and none of the suggestions were doing any good.
The fix was to assign the file to data instead of files.
def upload_app(path):
url, arn = create_signed_upload('ANDROID_APP')
headers = {'content-type': 'application/octet-stream'}
with open(path, 'rb') as app:
requests.put(url, data=app, headers=headers)
success = wait_on_upload(arn)
return success

Submitting a Training Job to Google Cloud ML

I have a code as below that I want to submit to Google cloud ml. I already tested their example and got results.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import tensorflow as tf
import numpy as np
# Data sets
I_TRAINING = "/home/android/Desktop/training.csv"
I_TEST = "/home/android/Desktop/test.csv"
# Load datasets.
training_set = tf.contrib.learn.datasets.base.load_csv(filename=I_TRAINING, target_dtype=np.int)
test_set = tf.contrib.learn.datasets.base.load_csv(filename=I_TEST, target_dtype=np.int)
# Specify that all features have real-value data
feature_columns = [tf.contrib.layers.real_valued_column("", dimension=2)]
# Build 3 layer DNN with 10, 20, 10 units respectively.
classifier = tf.contrib.learn.DNNClassifier(feature_columns=feature_columns,
hidden_units=[10, 20, 10],
n_classes=2,
model_dir="/tmp/my_model")
# Fit model.
classifier.fit(x=training_set.data, y=training_set.target, steps=2000)
# Evaluate accuracy.
accuracy_score = classifier.evaluate(x=test_set.data, y=test_set.target)["accuracy"]
print('Accuracy: {0:f}'.format(accuracy_score))
# Classify two new flower samples.
#new_samples = np.array(
# [[6.4, 3.2, 4.5, 1.5], [5.8, 3.1, 5.0, 1.7]], dtype=float)
#y = classifier.predict(new_samples)
#print('Predictions: {}'.format(str(y)))
It's a code to train and create a DNN model in tensorflow. I already tested it locally and received results. I put this code in a folder named trainer along with init.py file, and uploaded the folder to gs://bucket-ml/second_job/trainer. Second_job is the JOB_NAME.
Then, when I want to submit this as a job, I do this and get the following error:
gcloud beta ml jobs submit training ${JOB_NAME} \
--package-path=trainer \
--module-name=trainer.trainer \
--staging-bucket="${TRAIN_BUCKET}" \
--region=us-central1 \
--train_dir="${TRAIN_PATH}/train"
ERROR: (gcloud.beta.ml.jobs.submit.training)
Packaging of user python code failed with message:
running sdist
running egg_info
creating trainer.egg-info
writing trainer.egg-info/PKG-INFO
writing top-level names to trainer.egg-info/top_level.txt
writing dependency_links to trainer.egg-info/dependency_links.txt
writing manifest file 'trainer.egg-info/SOURCES.txt'
error: package directory 'trainer' does not exist
Try manually writing a setup.py file at your package root
and rerunning the command
I am not sure if the package-path and module-name are correct. Please advise me what to do. Thanks
Regards,
The --package-path argument to the gcloud command should point to a directory that is a valid Python package, i.e., a directory that contains an __init__.py file (often an empty file). Note that it should be a local directory, not one on GCS.
The --module argument will be the fully qualified name of a valid Python module within that package. You can organize your directories however you want, but for the sake of consistency, the samples all have a Python package named trainer with the module to be run named task.py.
The directory structure of the samples look like:
trainer/
__init__.py
task.py
__init__.py will likely be an empty file. task.py contains your code. Then you can submit your job as follows:
gcloud beta ml jobs submit training ${JOB_NAME} \
--package-path=trainer \
--module-name=trainer.task \
--staging-bucket="${TRAIN_BUCKET}" \
--region=us-central1 \
-- \
--train_dir="${TRAIN_PATH}/train"
You can choose whatever names you want for your package and modules, just make sure the names on disk and the gcloud arguments match up: top-level directory is --package-path and the file with your code to run is --module (without the .py suffix).
A few notes:
Note the extra '-- \'. That indicates that all following arguments should be passed through to your program. That is, --train_dir is NOT an argument to gcloud beta ml jobs submit training and will be passed as a flag to your program
If you intend to use train_dir, you'll need to add some flag parsing to your code, e.g., using argparse.
Files you read in the cloud need to be on GCS.
Although flag parsing gives you more flexibility, it's not required. You can hard code paths to filenames. Just make sure they point to objects on GCS (and then remove the --train_dir from the gcloud call)

GeoDjango: 'No such file or directory' when creating PostGIS spatial database template

I am working on MacOS Lion. I have successfully set up the KyngChaos libraries for Postgres and PostGIS, as per the official instructions with no problems.
I've reached the section on creating a spatial database template, and now I'm hitting a problem:
$ psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
/postgis.sql: No such file or directory
How can I debug this? Where does postgis.sql come from in the first place?
UPDATE:
I just made sure that POSTGIS_SQL_PATH was actually set, as follows:
$ POSTGIS_SQL_PATH=`pg_config --sharedir`/contrib/postgis-1.5
$ echo $POSTGIS_SQL_PATH
/usr/local/Cellar/postgresql/9.1.3/share/postgresql/contrib/postgis-1.5
$ psql -d template_postgis -f $POSTGIS_SQL_PATH/postgis.sql
/usr/local/Cellar/postgresql/9.1.3/share/postgresql/contrib/postgis-1.5/postgis.sql: No such file or directory
It looks as though /usr/local/Cellar/postgresql/9.1.3/share/postgresql/ exists but there is no contrib directory below it. Where does this come from?
It seems like you are not finding postgis. Start by searching for postgis.sql. If it is not found then install postgis. If it is found then set your path appropriately.