Tensorrt wit MNIST sample proyect do not fails inference validation - mnist

I am trying to build and run the tensorrt MNIST sample proyect (https://github.com/NVIDIA/TensorRT/tree/release/6.0/samples/opensource/sampleMNIST) but when I run it, it fails the inference because it always predict the same output (digit 8).
Here I show how I run the application and the output I get.
Thanks,
Esteban
poncos#electron:~/CLionProjects/tensorrt$ ./bin/sampleMNIST --datadir=./resources
&&&& RUNNING TensorRT.sample_mnist # ./bin/sampleMNIST --datadir=./resources
[08/25/2019-23:57:46] [I] Building and running a GPU inference engine for MNIST
[08/25/2019-23:57:47] [I] [TRT] Detected 1 inputs and 1 output network tensors.
[08/25/2019-23:57:47] [I] Input:
--:.:===-=.--=====.... .:..:
.::
###
#####
#######
# ##### ###
######## ###
##### ###
#### ###
### ###
# ###
###
###
###
###
###
###
###
###
###
#
[08/25/2019-23:57:47] [I] Output:
0:
1:
2:
3:
4:
5:
6:
7:
8: **********
9:
&&&& FAILED TensorRT.sample_mnist # ./bin/sampleMNIST --datadir=./resources
poncos#electron:~/CLionProjects/tensorrt$

Related

Result from pickle file throwing wrong results for new observation for DBSCAN clustering

I have build a DBSCAN clustering model, the output result and the result after using the pkl files are not matching
Below, for 1st record the cluster is 0
But after running it from 'pkl' file, it is showing predicted result as [-1]
Dataframe:
HD MC WT Cluster
200 Other 4.5 0
150 Pep 5.6 0
100 Pla 35 -1
50 Same 15 0
Code
######## Label encoder for column MC ##############
le = preprocessing.LabelEncoder()
df['MC encoded'] = le.fit_transform(df['MC'])
col_1 = ['HD','MC encoded','WT']
data = df[col_1]
data = data.fillna(value=0)
######### DBSCAN Clustering ##################
model = DBSCAN(eps=7, min_samples=2).fit(data)
outliers_df = pd.DataFrame(data)
print(Counter(model.labels_))
######## Predict ###############
x = model.fit_predict(data)
df["Cluster"] = x
####### Create model pkl files and dump ################
filename1 = '/model.pkl'
model_df = open(filename1, 'wb')
pickle.dump(model,model_df)
model_df.close()
######## Create Encoder pkl files and dump ############
output = open('/MC.pkl', 'wb')
pickle.dump(le, output)
output.close()
####### Load the model pkl file ##############
with open('model.pkl', 'rb') as file:
pickle_model = pickle.load(file)
########## Load Encoder pkl file ############
pkl_file = open('MC.pkl', 'rb')
le_mc = pickle.load(pkl_file)
pkl_file.close()
######## Function to predict new data ##############
def testing(HD,MC,WT):
test = {'HD':[HD],'MC':[MC], 'WT':[WT]}
test = pd.DataFrame(test)
test['MC_encoded'] = le_mc.transform(test['MC'])
pred_val = pickle_model.fit_predict(test[['HD','MC_encoded',WT]])
print(pred_val)
return(pred_val)
###### Predict with new observation ###########
pred_val = testing(200,'Other',4.5)
Resulting cluster
[-1]
Expected cluster
[0]
Clustering is not predictive.
If you want to classify new instances, use a classifier.
So in my opinion you are using it entirely on the wrong premises...
Nevertheless, your mistake is that you use the wrong function.
fit_predict literally means discard the old model, then fit, and return the labels. This is because of a pretty poor design of sklearn that conflates learning algorithms and the resulting models. A model should not have a fit method anymore, a training algorithm not a predict as there is no model yet...
Now if you fit to a dataset of fewer than min_samples points, they must all be noise (-1) by definition. You meant to use predict only - which does not exist, because DBSCAN does not predict for new data points.

Fit a sympy functions or convert it to python function

Let (cos(x)exp(x)) be any simpy function. I want to change the sympy function into the function (a*cos(x) exp(x)+b) and fit the parameters (a,b) to data.
I don't now, if there is a direct way, to fit a sympy function. The pip package symfit 0.2.3 is not working (https://symfit.readthedocs.io/en/stable/tutorial.html) - there is an error when trying to import parts of the packages.
One can use the sympy function lambdify to create a numpy function like this
from sympy import symbols
from sympy import cos, exp
from sympy import lambdify
x = symbols('x')
python_formula = lambdify(x,cos(x)*exp(x), 'numpy')
I would now multiply my parameters like
def function(x,a,b,python_formula):
return a*python_formula(x) +b
Unfortunately, if I use scipy.optimize.curve_fit like
optimizedParameters, pcov = opt.curve_fit(function, x_data, y_data);
it will take the "python_formula" argument in my function as an optimizable parameter and will crash. I also did not find a way, to specify the fit parameter
(https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html).
If you have an idea, how to generally fit a sympy function or a way to fix the code, I would be thankful to hear it.
You need to use a function factory, so that the lambdified function is bound at the moment of the definition and not when your script is sourced
from sympy import symbols
from sympy import cos, exp
from sympy import lambdify
from scipy.optimize import curve_fit
### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
def make_f2opt(lambdified):
return lambda x, a, b: a*lambdified(x)+b
### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
x = symbols('x')
python_formula = lambdify(x,cos(x)*exp(x), 'numpy')
### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
f2opt = make_f2opt(python_formula)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
parameter, covariance = curve_fit(f2opt, x_data, y_data)

Google AI Adventures code for simple Estimator for iris flower ValueError: invalid literal for int() with base 10: 'Sepal length'

This is regarding an issue of the code which has been shown in this video. I tried to run the code in TensorFlow (version 1.12 and 1.3) with python (version 3.7 and 3.6.4). But I get an error like below
"ValueError: invalid literal for int() with base 10: 'Sepal length'".
When I was running the code in TensorFlow version 1.12, I realized an additional warning/error which went into different code files to spit the mistake.
#Code
import tensorflow as tf
import numpy as np
print (tf.__version__)
from tensorflow.contrib.learn.python.learn.datasets import base
# Data files
IRIS_TRAINING = "iris_training.csv"
IRIS_TEST = "iris_test.csv"
# Load datasets.
training_set = base.load_csv_with_header(filename=IRIS_TRAINING,
features_dtype=np.float32,
target_dtype=np.int)
test_set = base.load_csv_with_header(filename=IRIS_TEST,
features_dtype=np.float32,
target_dtype=np.int)
print(training_set.data)
print(training_set.target)
Traceback
# 1.3.0
# ValueError Traceback (most recent call last)
# <ipython-input-2-065d21e0a8b0> in <module>
# 13 training_set = base.load_csv_with_header(filename=IRIS_TRAINING,
# 14 features_dtype=np.float32,
# ---> 15 target_dtype=np.int)
# 16 test_set = base.load_csv_with_header(filename=IRIS_TEST,
# 17 features_dtype=np.float32,
# c:\users\sanjay\appdata\local\programs\python\python36\lib\site-packages\tensorflow\contrib\learn\python\learn\datasets\base.py in load_csv_with_header(filename, target_dtype, features_dtype, target_column)
# 46 data_file = csv.reader(csv_file)
# 47 header = next(data_file)
# ---> 48 n_samples = int(header[0])
# 49 n_features = int(header[1])
# 50 data = np.zeros((n_samples, n_features), dtype=features_dtype)
# ValueError: invalid literal for int() with base 10: 'Sepal length'
Figured it out, the data file has to be formatted differently "sepal length" was my column header name. I had prepared it from: https://en.wikipedia.org/wiki/Iris_flower_data_set
Instead of that using these files, the code works.
http://download.tensorflow.org/data/iris_training.csv, http://download.tensorflow.org/data/iris_test.csv

Style Transfer using tensorflow for model inception?

I have written code which I am trying to make it work from many weeks, the problem is with the update on input not working.
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
### END CODE HERE ###
# Run the noisy input image (initial generated image) through the model. Use assign().
### START CODE HERE ### (1 line)
init_fn(sess)
sess.run(input_img.assign(inputo))
### END CODE HERE ###
for i in range(num_iterations):
generated_image,_ = sess.run([input_img,train_step])
if i%20 == 0:
Jt, Jc, Js = sess.run([Jolo, content_loss, style_losss])
Model Definition is done in this section, where I have defined shared Variable, and loaded inception v1 model from tf.slim
with tf.variable_scope('input') as scope:
input_img = tf.get_variable('in_img',shape=([1, img_height, img_width, 3]),dtype=tf.float32,initializer=tf.zeros_initializer())
with slim.arg_scope(inception.inception_v1_arg_scope()):
_, end_points = inception.inception_v1(input_img, num_classes=1001, is_training=False)
# Create an operation that loads the pre-trained model from the checkpoint
init_fn = slim.assign_from_checkpoint_fn(
os.path.join('home/n/models/inception_/', '/home/n/data/inception_v1.ckpt'),
slim.get_model_variables('InceptionV1')
)
I am doing something wrong, and because of it update never happens.
Thank you

Adding y-axis to multiple offset ytics in gnuplot?

I am searching for a while to get my plot done as I like to have it. Actually, I have a left y-axis and two right y-axis based on the example given here: How to plot multiple y-axes? The information I got there did the job as I would like to have it. However, in my plot I would like to have the y-axis for the 2nd y-values on the right hand side too. I was searching around and found this one: multiple Y axis - margin which is not related to gnuplot. So right now I don't know how to do it except, I will use a vector and build the axis myself which might be not accurate in terms of positioning and not the best way to go. The question now is, if I can move the right border of the graph using an offset like I do it with the ytics and ylabels? The help of gnuplot does not provide anything for the »border« but I might also search at the wrong place.
The picture and gnuplot script is given below. However, I am not allowed to show the graphs but it does not play a role here. To sum up: I would like to have the red added line in my eps file at the end and I am wondering if this is possible without using arrows and building it myself. In addition I hope that this question may be relevant for others and was not asked and solved previously. Otherwise my search-investigation was bad. Thank you in advance.
#!/bin/gnuplot
#
# Tobias Holzmann
# 05.09.2017
# Multiplot for 3 y-axis
#
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
clear
reset
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
set output "PowerControl.tex"
set terminal epslatex
set key nobox
set ytics out
set y2tics out
set ytics nomirror
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
set style line 1 lw 1.7 lc rgb 'black' ps 0.7 pt 7
set style line 2 lw 1.5 lc rgb 'black'
set style line 3 lw 1.3 lc rgb 'black' dashtype 4
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
set multiplot
set xrange [0:60]
set rmargin screen 0.8
set lmargin screen 0.10
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
set xlabel "Time [s]"
set ylabel "Amount of inserted energy [-]"
set ylabel offset 3,0
set yrange [0:.4]
set ytics \
("None" 0.00, "" 0.05, "" 0.1, "" 0.15, "Moderate" 0.2, \
"" 0.25, "" 0.3, "" 0.35, "High" 0.4)
unset y2tics
set key at graph 0.95,0.22
set key height 0.3
plot \
"timePower" using 1:2 w lp ls 1 t 'Energy insertion'
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#unset ytics
#unset xtics
unset ylabel
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
set grid
set y2tics 10
set y2tics out
set y2range [0:80]
set y2label "Von Mises Stress [MPa]"
set key at graph 0.95,0.315
set key height 6
plot \
"timeVonMises" using 1:2 w l ls 2 t 'Von Mises Stress' axis x1y2
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
unset grid
unset ytics
unset ylabel
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
set y2tics 75
set y2range [0:600]
set y2tics offset 8, 0
set y2label "Maximum Temperature [$^{\\circ} $C]" offset 8,0
set key at graph 0.95,0.10
set key height 0.3
plot \
"timeTMax" using 1:($2-273.15) w l ls 3 t 'Temperature' axis x1y2
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
unset multiplot
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Multiplot with Gnuplot without 2nd y-axis
PS: Based on my low level of reputation points, I am not allowed to put the picture directly (unfortunately).
For the last data set you can first draw the data without showing the y2 axis, and then make a separate plot that shows only the y2 axis and no data. You are then free to position the two plots relative to one another. It is important to make sure that both plots use the same height (which can be done be setting the top and bottom margins) and the same numerical range (which is trivial if you fix the range, or you can use writeback/restore if you want to use autoscaling of the y2 axis).
Example:
reset
set multiplot
# first, draw the graph without y2 axis
set tmargin 1
set bmargin 3
set rmargin 20
set xtics nomirror
unset ytics
unset y2tics
unset key
set border 1 # draw only the bottom border (the x axis)
set y2range [] writeback # use autoscaling for y2 and store the range
plot sin(x) axes x1y2
# now draw only the y2 axis, with the range from the previous plot
set y2range restore
set rmargin 10
set border 8 # draw only the right border (the y2 axis)
unset xtics
set y2tics
plot 1/0 axes x1y2
unset multiplot
gives
After checking the manpage of gnuplot etc. I think there is no possibility how I would like to have it. However, a fast an easy workaround is using (as already mentioned vectors with do [] {}. My suggestion is as follows:
set arrow 1 from graph 1.20,0 to graph 1.20,1 nohead lw 1
do for [i=0:8] {
set arrow from graph 1.20,i/8. to graph 1.21,i/8. nohead lw 1
}
The outcome is given in the picture above (or link). Maybe someone can use it for the individual plots one may want to make. If someone knows an better solution, please let us know.
Kind regards
Tobias
3rd y-axis with arrows and do

Resources