I tried the following code in nvidia-dgx2 machine.
import cirq
# Pick a qubit.
qubit = cirq.GridQubit(0, 0)
# Create a circuit
circuit = cirq.Circuit(
cirq.X(qubit)**0.5, # Square root of NOT.
cirq.measure(qubit, key='m') # Measurement.
)
print("Circuit:")
print(circuit)
# Simulate the circuit several times.
simulator = cirq.Simulator()
result = simulator.run(circuit, repetitions=20)
print("Results:")
print(result)
But, I get the attribute error.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_36197/3759634386.py in <module>
2
3 # Pick a qubit.
----> 4 qubit = cirq.GridQubit(0, 0)
5
6 # Create a circuit
AttributeError: module 'cirq' has no attribute 'GridQubit'
Any solution to this issue?
Related
I had been trying to replicated an online tutorial for plotting confusion matrix but got recursion error, tried resetting the recursion limit but still the error persists. The code is a below:
log = LogisticRegression()
log.fit(x_train,y_train)
pred_log = log.predict(x_train)
confusion_matrix(y_train,pred_log)
The error I got is :
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
<ipython-input-57-4b8fbe47e72d> in <module>
----> 1 (confusion_matrix(y_train,pred_log))
<ipython-input-48-92d5242f8580> in confusion_matrix(test_data, pred_data)
1 def confusion_matrix(test_data,pred_data):
----> 2 c_mat = confusion_matrix(test_data,pred_data)
3 return pd.DataFrame(c_mat)
... last 1 frames repeated, from the frame below ...
<ipython-input-48-92d5242f8580> in confusion_matrix(test_data, pred_data)
1 def confusion_matrix(test_data,pred_data):
----> 2 c_mat = confusion_matrix(test_data,pred_data)
3 return pd.DataFrame(c_mat)
RecursionError: maximum recursion depth exceeded
The shape of the train and test data is as below
x_train.shape,y_train.shape,x_test.shape,y_test.shape
# ((712, 7), (712,), (179, 7), (179,))
Tried with: sys.setrecursionlimit(1500)
But still no resolution.
Looks like you are recursively calling the same function. Try changing the outer function name.
1 def confusion_matrix(test_data,pred_data):
----> 2 c_mat = confusion_matrix(test_data,pred_data)
3 return pd.DataFrame(c_mat)
To
def confusion_matrix_pd_convertor(test_data,pred_data):
c_mat = confusion_matrix(test_data,pred_data)
return pd.DataFrame(c_mat)
log = LogisticRegression()
log.fit(x_train,y_train)
pred_log = log.predict(x_train)
confusion_matrix_pd_convertor(y_train,pred_log)
I am trying to use Google Colab to build a model for use on a Google Coral device. In order to do this I need to freeze the Graph and then convert it to TfLite. I can successfully create the model and test it using the tutorial but I cannot figure out how to Freeze the graph. At the end of the tutorial the model is saved in the Saved_Model format. My Google Colab notebook is available here: https://drive.google.com/file/d/1F6wvz4yUp6Iz2hY3n7bQYnYBJe7H5JUE/view?usp=sharing
I have tried a variety of code samples I have found on the web but all have ended in errors. Currently I am trying this code to freeze the graph
from tensorflow.python.tools import freeze_graph
from tensorflow.python.saved_model import tag_constants
input_saved_model_dir = export_path
output_node_names = "dense/Softmax"
input_binary = True
input_saver_def_path = False
restore_op_name = None
filename_tensor_name = None
clear_devices = False
input_meta_graph = False
checkpoint_path = None
input_graph_filename = None
saved_model_tags = tag_constants.SERVING
output_graph_filename = "./frozenGraph.pb"
freeze_graph.freeze_graph(input_graph_filename, input_saver_def_path,
input_binary, checkpoint_path, output_node_names,
restore_op_name, filename_tensor_name,
output_graph_filename, clear_devices, "", "", "",
input_meta_graph, input_saved_model_dir,
saved_model_tags)
But I get the error:
NotFoundError Traceback (most recent call last)
NotFoundError: Key module/MobilenetV2/Conv/BatchNorm/beta not found in checkpoint
[[node save_2/RestoreV2 (defined at /usr/local/lib/python3.6/dist-packages/tensorflow_hub/native_module.py:451) ]]
It also mentions this error
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saving/saveable_object_util.py in op_list_to_dict(op_list, convert_variable_to_tensor)
286 if name in names_to_saveables:
287 raise ValueError("At least two variables have the same name: %s" %
--> 288 name)
289 names_to_saveables[name] = var
290
ValueError: At least two variables have the same name: dense/bias
I am trying to classify images using sift feature descriptors with the help of
opencv3 and python3.
My code is like this
#some previous lines of code above...
import cv2.ml
print("svm items", len(train_desc), len(train_desc[0]))
count=0
svm = cv.ml.SVM_create()
svm.setType(cv2.ml.SVM_C_SVC)
svm.setKernel(cv2.ml.SVM_LINEAR)
svm.setTermCriteria((cv.TERM_CRITERIA_COUNT, 100, 1.e-06))
svm.train(np.array(train_desc), cv.ml.ROW_SAMPLE ,np.array(train_labels))
i=0
j=0
confusion = np.zeros((40,40))
def classify(pth):
feature = feature_extract(pth)
p = svm.predict(feature)
confusion[train_labels[count]-1,p-1] = confusion[train_labels[count]-1,p-1] +1
for p in training_paths:
classify(p)
count+=1
Then I got this error
TypeError Traceback (most recent call last)
<ipython-input-78-511fc16d25b1> in <module>()
1 for p in training_paths:
----> 2 classify(p)
3 count+=1
<ipython-input-77-e2187ad1b52e> in classify(pth)
3 feature = feature_extract(pth)
4 p = svm.predict(feature)
----> 5 confusion[train_labels[count]-1,p-1] = confusion[train_labels[count]-1,p-1] +1
TypeError: unsupported operand type(s) for -: 'tuple' and 'int'
I was trying to implement the code from this github account
I have created a RDD named Distance . All are float values. I intend to add them and find the total sum .
print(Distance.take(5))
Output : [802.0, 1055.0, 919.0, 204.0, 951.0]
print(sum(Distance.take(5)))
Output : 3931.0
totalDistance=Distance.reduce(lambda x,y:(x+y))
Output: Py4JJavaError Traceback (most recent call last)
<ipython-input-29-874f9e382e38> in <module>()
2 # Reduce takes a function that acts on two elements and returns an object of same type.
3
----> 4 totalDistance=Distance.reduce(lambda x,y:(x+y))
Using anaconda distribution, Python 3.61 and using Jupyter notebook for Scipy/Numpy. I can use the print(' blah {} '.format(x)) to format numbers but if I iterate over a nparray I get an error.
# test of formatting
'{:+f}; {:+f}'.format(3.14, -3.14) # show it always
example stolen from the Python 3.6 manual section 6.1.3.2 Here and I get the expected response. So I know that it isn't that I've forgotten to import something i.e. it is built in.
if I do this:
C_sense = C_pixel + C_stray
print('Capacitance of node')
for x, y in np.nditer([Names,C_sense]):
print('The {} has C ={} [F]'.format(x,y))
I get output
Capacitance of node
The 551/751 has C =8.339999999999999e-14 [F]
The 554 has C =3.036e-13 [F]
The 511 has C =1.0376e-12 [F]
But if I do this:
# now with formatting
C_sense = C_pixel + C_stray
print('Capacitance of node')
for x, y in np.nditer([Names,C_sense]):
print('The {} has C ={:.3f} [F]'.format(x,y))
I get the following error:
TypeError Traceback (most recent call last)
<ipython-input-9-321e0b5edb03> in <module>()
3 print('Capacitance of node')
4 for x, y in np.nditer([Names,C_sense]):
----> 5 print('The {} has C ={:.3f} [F]'.format(x,y))
TypeError: unsupported format string passed to numpy.ndarray.__format__
I've attached a screen shot of my Jupyter notebook to show context of this code.
The error is clearly coming from the formatter, not knowing what to do with the numpy iterable you get from np.nditer.
Does the following work?
for x,y in zip(Names,C_sense):
print('The {} has C ={:.3f} [F]'.format(x,y))