NameError: name 'custom_data_home' is not defined - python

from sklearn.datasets import fetch_mldata
mnist = fetch_mldata('MNIST original', data_home=custom_data_home)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
mnist = fetch_mldata('MNIST original', data_home=custom_data_home)
NameError: name 'custom_data_home' is not defined
i am getting NameError, i searched in net for solutions, i didn't get any relevant answers.
i even tries installing "custom_data_home" using easy_install . it says it could not find.
pls help me on this.

I don't know anything about sklearn, but it looks like you are trying to use the example from this page: http://scikit-learn.org/stable/datasets/mldata.html
In that example custom_data_home is a variable containing the path to where you want the data stored. If you leave it off it says it should default to just data.
Basically in your script you have not defined custom_data_home. That is what NameError is telling you.
If you are going to use a variable, like custom_data_home you have to define it in some way. Your script doesn't know what custom_data_home is.
custom_data_home = '/path/to/my/data'
mnist = fetch_mldata('MNIST original', data_home=custom_data_home)
That should work.

Related

Nltk is installed but nltk_utils returns ModuleNotFoundError

I am using virtual env, I have installed nltk module with pip3, when I am trying to import nltk_utils I am getting a ModuleNotFoundError
>>> import nltk
>>> import nltk_utils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'nltk_utils'
I have tried without virtualenv too but no luck
OS : Ubuntu
Python Version : 3.9.5
GCC : 10.3.0
nltk_utils is nothing that comes shipped with nltk. Did you mean nltk.util, which is described here?
Otherwise nltk_utils is used in some examples using nltk where it is a custom file that contains useful functions in interacting with nltk (E.g. in this chatbot example) so if you are following some tutorial or similar, check if they mention somewhere what nltk_utils should contain
Adding to the answer of user FlyingTeller:
I came here having the same problem, and i followed the exact same tutorial as linked by user FlyingTeller. The referenced import "nltk_utils" is a custom file made in the scope of the tutorial.
Solving the problem:
You can find "nltk_utils" at the github of the tutorial creator, here:
https://github.com/patrickloeber/pytorch-chatbot/blob/master/nltk_utils.py
(for more explanation about that file, check the video that is linked in the tutorial).
Update:
You also need the file "model.py", which is found at the above linked github, too.
After that, you may still face errors, in my case i needed to move the "# train model" part into main and also cast the labels to int. The adjusted code looks as follows:
...
if __name__ == '__main__':
# Train the model
for epoch in range(num_epochs):
for (words, labels) in train_loader:
words = words.to(device)
labels = labels.type(torch.LongTensor) # <- Fix from here: https://stackoverflow.com/a/71149364/18456868
labels = labels.to(device)
# Forward pass
outputs = model(words)
...
After that, i got it working:
Output of script after about 3 minutes of training

Tensorflow Backend - Bug in "model._make_predict_function"

there's is a bug while running the Tensorflow code, the error code appears like this:
Traceback (most recent call last):
File "app.py", line 76, in <module>
model = deepmoji_emojis(maxlen, PRETRAINED_PATH)
File "/home/lifeofpy/LifeofPy/AI Photographer Project/Text-to-Color/deepmoji/model_def.py", line 35, in deepmoji_emojis
model._make_predict_function()
AttributeError: 'Functional' object has no attribute '_make_predict_function
and the file app.py is like this:
# print('Loading model from {}.'.format(PRETRAINED_PATH))
model = deepmoji_emojis(maxlen, PRETRAINED_PATH)
model.summary()
model._make_predict_function()
I think the error message is occured by the function 'model._make_predict_function',
I would appreciate any comments on this issue. Thanks!
Use: model.make_predict_function()
instead of: model._make_predict_function()
I tried to find _make_predict_function() with Google and it seems it was private function in old Keras in keras.engine.training.py but now Keras is part of tensorflow and function was removed from code. I can't find _make_predict_function() in tensorflow.keras.engine.training.py
Some old posts suggest to use model.predict() instead of model._make_predict_function() before threads but other posts suggest to duplicate model for every thread. But maybe new code in tensorflow resolved problem with running it in threads and maybe it doesn't need this function any more.

Setting up VGG-Face Descriptor in PyTorch

I've been trying to use the VGG-Face descriptor model (http://www.robots.ox.ac.uk/~vgg/software/vgg_face/) for a project of mine. All I want to do is to simply obtain the outputs of the network from an input image.
I haven't used any of MatConvNet, Caffe or PyTorch before and so I picked PyTorch at random. It turns out that the model (of class torch.legacy.nn.Sequential.Sequential) was saved in an older version of PyTorch and the syntax was thus slightly different to the ones on PyTorch's documentation.
I was able to load the lua .t7 model like so:
vgg_net = load_lua('./vgg_face_torch/VGG_FACE.t7', unknown_classes=True)
And loading in the input image:
# load image
image = imread('./ak.png')
# convert to tensor
input = torch.from_numpy(image).float()
Gleefully, I loaded in the image into the model with much anticipation:
# load into vgg_net
output = vgg_net.forward(input)
However, my hopes of it cooperating at all was quickly dashed when the code fails to compile. Leaving behind a cryptic error message:
Traceback (most recent call last):
File "~/Documents/python/vgg-face-test/vgg-pytorch.py", line 25, in <module>
output = vgg_net.forward(input)
File "~/.local/lib/python3.6/site-packages/torch/legacy/nn/Module.py", line 33, in forward
return self.updateOutput(input)
File "~/.local/lib/python3.6/site-packages/torch/utils/serialization/read_lua_file.py", line 235, in updateOutput_patch
return obj.updateOutput(*args)
File "~/.local/lib/python3.6/site-packages/torch/legacy/nn/Sequential.py", line 36, in updateOutput
currentOutput = module.updateOutput(currentOutput)
TypeError: 'NoneType' object is not callable
Of which I am absolutely dumbfounded by.
This is why I sought help on Stackoverflow. I hope someone here could perhaps lend me a hand in setting up the model - not even necessarily in Torch, in fact any working model will do, where I can simply get the description for any particular image.
try output = vgg_net(input) without the forward.
This apparently calls a default method defined in the module but I'm having trouble understanding why this is necessary.

Tensorflow's API: seq2seq

I have been following https://github.com/kvfrans/twitch/blob/master/main.py tutorial to create and train a chatbot based on rnn using tensorflow. From what I understand, the tutorials was written on an older version of tensorflow, so some parts are outdated and give me an error like:
Traceback (most recent call last):
File "main.py", line 33, in <module>
outputs, last_state = tf.nn.seq2seq.rnn_decoder(inputs, initialstate, cell, loop_function=None, scope='rnnlm')
AttributeError: 'module' object has no attribute 'seq2seq'
I fixed some of them, but can't figure out what is the alternative to tf.nn.seq2seq.rnn_decoder and what should be the new module's parameters. What I currently fixed:
tf.nn.rnn_cell.BasicLSTMCell(embedsize) changed to
tf.contrib.rnn.BasicLSTMCell(embedsize)
tf.nn.rnn_cell.DropoutWrapper(lstm_cell,keep_prob) changed to tf.contrib.rnn.DropoutWrapper(lstm_cell,keep_prob)
tf.nn.rnn_cell.MultiRNNCell([lstm_cell] * numlayers) changed to
tf.contrib.rnn.MultiRNNCell([lstm_cell] * numlayers)
Can someone please help me figure out what tf.nn.seq2seq.rnn_decoder will be?
I think this is the one you need:
tf.contrib.legacy_seq2seq.rnn_decoder

input syntax in paraview python shell

I currently am trying to use
paraview.simple.Histogram(Input, params)
as
paraview.simple.Histogram(q, BinCount = 30)
in the shell where q is a variable data set from my "out.e" ExodusII file. I'm getting the error
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'q' is not defined
I've tried to search the literature on python shell scripting in Paraview but it seems to be eluding me. I know this is a quick fix. Thanks
Try this instead:
Histogram(SelectInputArray="q", BinCount=30)
This assumes you currently have the reader as the active object in the Pipeline browser.
I was able to answer this problem using the following.
outset = Reader(FileName=['/dir/out.e'])
and for the Histogram
histogram1_1 = Histogram(Input=outset)
histogram1_1.SelectInputArray = ['CELLS', 'q']
histogram1_1.BinCount = 30
Note for anyone who comes into this issue, the TRACE option in the Python Shell will build a script for you when you do anything in the GUI.

Categories