Tensorflow.compat.v2.__internal__.tracking' has no attribute 'TrackableSaver' Error - python

I got this error after installing Tensorflow.js. Previously this program was working. Could it be a problem with the versions? I'm really curious as to what's causing it.
Thanks in advance.
File ~\OneDrive\Masaüstü\Bitirme Proje\neural_network(sinir_ağları).py:61
model = build_model()
File ~\OneDrive\Masaüstü\Bitirme Proje\neural_network(sinir_ağları).py:29 in build_model
model = keras.Sequential([
File C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\trackable\base.py:205 in _method_wrapper
result = method(self, *args, **kwargs)
File C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\traceback_utils.py:67 in error_handler
raise e.with_traceback(filtered_tb) from None
File C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\training.py:3331 in saver_with_op_caching
return tf.__internal__.tracking.TrackableSaver(
AttributeError: module 'tensorflow.compat.v2.__internal__.tracking' has no attribute 'TrackableSaver'
I was planning to convert my model with Tensorflow.js and run it over the web. But when I installed Tensorflow.js I got this error in the program.

Update keras with pip install 'keras>=2.9.0' for keras-team/keras#af70910.
- self._trackable_saver = saver_with_op_caching(self)
+ self._checkpoint = tf.train.Checkpoint(root=weakref.ref(self))

I had to create another environment on Jupyter and re-install all the libraries from scratch since it seemed all the libraries started having issues, not just TensorFlow. It is now working with no errors.

Related

deploy.prototxt in Caffe model

I am running into this problem when running my code:
model = cv2.dnn.readNetFromCaffe("deploy.prototxt", "res10_300x300_ssd_iter_140000.caffemodel")
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\caffe\caffe_io.cpp:1126: error: (-2:Unspecified error) FAILED: fs.is_open(). Can't open "deploy.prototxt" in function 'cv::dnn::ReadProtoFromTextFile'
I Believe it is coming from when I run this line of code and am not sure what to do about it. I thought it was because I didn't have this file saved with the code but I am not entirely sure what this file is and does:
# Load the SSD model
model = cv2.dnn.readNetFromCaffe("deploy.prototxt", "res10_300x300_ssd_iter_140000.caffemodel")

openVino: __cinit__() got an unexpected keyword argument 'weights'

I'm trying to run this repo but found an error.
PPE-detector-Tiny-YOLOv3-Rasp.erry-PI-and-NCS2
I never used python before. when I run the PPE_Detector_Pc.py I got an error like this :
PS D:\repository\PPE-detector-Tiny-YOLOv3-Rasp.erry-PI-and-NCS2> py PPE_Detector_Pc.py
loading the model...
loading plugin on Intel NCS2...
Traceback (most recent call last):
File "PPE_Detector_Pc.py", line 406, in <module>
sys.exit(main_IE_infer() or 0)
File "PPE_Detector_Pc.py", line 201, in main_IE_infer
net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
File "ie_api.pyx", line 1598, in openvino.inference_engine.ie_api.IENetwork.__cinit__
TypeError: __cinit__() got an unexpected keyword argument 'weights'
this is the part where it gave me error:
path_to_xml_file = "tiny_yolo_IR_500000_FP32.xml" #<--- MYRIAD
path_to_bin_file = os.path.splitext(path_to_xml_file)[0] + ".bin"
time.sleep(1)
print("loading plugin on Intel NCS2...")
plugin = IECore()
net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file)
input_blob = next(iter(net.inputs))
exec_net = plugin.load(network=net)
my path_to_xml_file and path_to_bin_file was using tiny_yolo_IR_500000_FP32.xml and tiny_yolo_IR_500000_FP32.bin i put in same folder i downloaded from the repo.
I just changed IEPlugin to IECore because it is no longer supported on the newer version openVino.
is there anything I miss on that?
The repository you've provided is not maintained by OpenVINO™ and is using deprecated APIs.
You're partially correct on steps to replace IEPlugin with IECore. Here are the full steps required to read and load networks using IECore API:
ie = IECore()
net = ie.read_network(model=model_xml, weights=model_bin)
exec_net = ie.load_network(network=net, device_name="CPU", num_requests=2)
The provided IR models (.xml and .bin files) from the repository are also in deprecated version as they are IR version 5 as shown here when running the edited code in OpenVINO™ Development Tools 2022.1:
To avoid this error, you will need to convert the original model into the latest IR format (IR v11) using OpenVINO™ 2022.1 Model Optimizer.

TensorFlow/Keras: How to get missing models (ResNet101, ResNeXt, etc.) from Keras' applications module?

A number of documented Keras applications are missing from my (up-to-date) Keras installation and TensorFlow 1.10 Keras API installation.
I import Keras' applications module as suggested and use it as follows:
from keras import applications
resnet = applications.ResNeXt101(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
I also tried
resnet = applications.resnext.ResNeXt101(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
But in both cases I get the same type of error:
AttributeError: module 'keras.applications' has no attribute 'ResNeXt101'
Printing help(applications) yields:
Help on package keras.applications in keras:
NAME
keras.applications
PACKAGE CONTENTS
densenet
imagenet_utils
inception_resnet_v2
inception_v3
mobilenet
mobilenet_v2
mobilenetv2
nasnet
resnet50
vgg16
vgg19
xception
FUNCTIONS
DenseNet121 = wrapper(*args, **kwargs)
DenseNet169 = wrapper(*args, **kwargs)
DenseNet201 = wrapper(*args, **kwargs)
InceptionResNetV2 = wrapper(*args, **kwargs)
InceptionV3 = wrapper(*args, **kwargs)
MobileNet = wrapper(*args, **kwargs)
MobileNetV2 = wrapper(*args, **kwargs)
NASNetLarge = wrapper(*args, **kwargs)
NASNetMobile = wrapper(*args, **kwargs)
ResNet50 = wrapper(*args, **kwargs)
VGG16 = wrapper(*args, **kwargs)
VGG19 = wrapper(*args, **kwargs)
Xception = wrapper(*args, **kwargs)
keras_modules_injection(base_fun)
which shows that the models initially aren't present in my installation. Why not? They're also not packaged in the TensorFlow's Keras API.
I tried copying the files from the Keras applications GitHub repository and pasting them in site-packages/keras/applications/, but this results in the following stacktrace:
File "myscript.py", line 517, in get_fpn
resnet = applications.resnext.ResNeXt101(include_top=False, weights='imagenet', input_shape=(SCALED_HEIGHT, SCALED_WIDTH, 3), pooling=None)
File "site-packages/keras/applications/resnet_common.py", line 575, in ResNeXt101
**kwargs)
File "site-packages/keras/applications/resnet_common.py", line 348, in ResNet
data_format=backend.image_data_format(),
AttributeError: 'NoneType' object has no attribute 'image_data_format'
Any ideas on how to fix this? Why aren't these included and working in default installations of either Keras or TensorFlow? Why does the documentation not explain this?
Reason for the problem:
The backend object is None at line 348.
My guess is you tried something like this:
>>> from keras_applications import resnext
>>> resnext.ResNeXt101(weights=None)
The backend information is injected from keras.applications to keras_applications via the keras_modules_injection decorator.
https://github.com/keras-team/keras/blob/c658993cf596fbd39cf800873bc457e69cfb0cdb/keras/applications/resnext.py#L17
Procedure to fix the problem:
Make sure the keras & keras applications versions are as follows:
>>pip list |grep Keras
Keras 2.2.4
Keras-Applications 1.0.8
If they're not, upgrade using
>>pip install --upgrade keras keras-applications
Update the changes from this pull request, https://github.com/keras-team/keras/pull/11203/files into site-packages/keras/applications
from keras import applications
resnext = applications.resnext.ResNeXt101(include_top=False, weights=None, input_shape=(299,299,3))
print(type(resnext))

OSError unable to create file - invalid argument

I am using Python and Keras on top of Tensorflow to train my neural networks.
When I switched from Ubuntu 16.04 to Windows 10, my model could not be saved anymore when I run the following:
filepath = "checkpoint-"+str(f)+model_type+"-"+optimizer_name+"-{epoch:02d}-{loss:.3f}.hdf5"
checkpoint = ModelCheckpoint(filepath, monitor='loss', verbose=1, save_best_only=True, mode='min')
callbacks_list = [checkpoint]
and later on:
model.fit(X, y,
batch_size=128,
epochs=1,
shuffle=False,
callbacks=callbacks_list)
I get this Error:
OSError: Unable to create file (Unable to open file: name = 'checkpoint-<_io.textiowrapper name='data/swing-projects100-raw/many-chunks/log-gamma-f3.txt' mode='a' encoding='cp1252'>2l128-adam-0.001-{epoch:02d}-{loss:.3f}.h5', errno = 22, error message = 'invalid argument', flags = 13, o_flags = 302)
I have Keras 2.0.8 and h5py 2.7.0 installed via conda.
I tried
filepath = "checkpoint-"+str(f)+model_type+"-"+optimizer_name+"-{epoch:02d}-{loss:.3f}.hdf5"
with open(filepath, "w") as f:
f.write("Test.")
and got a similar error:
OSError: [Errno 22] Invalid argument: "checkpoint-<_io.TextIOWrapper name='data/swing-projects100-raw/many-chunks/log-gamma-f3.txt' mode='a' encoding='cp1252'>2L128-Adam-0.001-{epoch:02d}-{loss:.3f}.hdf5"
When I removed str(f) from the filepath, it worked.
f is an Integer and I don't know why it caused the error, but removing it from the string solved my problem.
Let me know if you know exactly why.
I had a similar problem with this code:
agent.save("./saved_models/weights_episode_{}.h5".format(e))
I solved it by manually creating the folder saved_models
e being an integer did not cause any problems in my case.
I have the similar problem when using tensorflow on a distant machine.
the reason of my maybe 'have no permission to modify the file'.
I solve this problem by use the save path like "../model.h5"———the folder where you have permission.
may this helps someone.

Script Error when run https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/label_image.py

I try to retrain Inception's Final Layer for New Categories by reference the following doc
My OS: Windows 10 X64 Enterprise
Python 3.6.2 by Anaconda 4.4
Tensorflow : 1.3.0 (CPU-Only Version)
When I use new images that collect by me and finish the training, I use following commend to test, but failed!
(tensorflow13) C:\Users\James\Tensorflow\model-retrain\tensorflow-for-poets-2\scripts>python .\label_image.py --image c:\Users\James\Tensorflow\sample_img\Panda001.jpg --graph c:\Users\James\Tensorflow\model-retrain\tensorflow-for-poets-2\scripts\retrained_graph.pb --labels C:\Users\James\Tensorflow\model-retrain\tensorflow-for-poets-2\scripts\retrained_labels.txt
Error Message:
2017-09-01 09:27:46.902115: I C:\tf_jenkins\home\workspace\nightly-win\M\windows\PY\36\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
Traceback (most recent call last):
File ".\label_image.py", line 120, in <module>
input_operation = graph.get_operation_by_name(input_name);
File "C:\Users\James\AppData\Local\conda\conda\envs\tensorflow13\lib\site-packages\tensorflow\python\framework\ops.py", line 3225, in get_operation_by_name
return self.as_graph_element(name, allow_tensor=False, allow_operation=True)
File "C:\Users\James\AppData\Local\conda\conda\envs\tensorflow13\lib\site-packages\tensorflow\python\framework\ops.py", line 3097, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "C:\Users\James\AppData\Local\conda\conda\envs\tensorflow13\lib\site-packages\tensorflow\python\framework\ops.py", line 3157, in _as_graph_element_locked
"graph." % repr(name))
KeyError: "The name 'import/input' refers to an Operation not in the graph."
Does anyone has same problem ?
For some reason retrained_graph.pb doesn't have the input the script expects it to have. Probably it was built slightly differently from what the tutorials expect (specifically around how the meta graph was imported).
Updated link to script
The problem here is that your inputs/outputs are probably wrong, the script is using this ones:
input_name = "file_reader"
output_name = "normalized"
If you trained this model you might need to find your inputs/outputs as they are likely to be different.
I dont know the best way to find this out but this code has help me a before:
import tensorflow as tf
frozen='/tensorflow/mobilenets/mobilenet_v1_1.0_224.pb'
gf = tf.GraphDef()
gf.ParseFromString(open(frozen,'rb').read())
[n.name + '=>' + n.op for n in gf.node if n.op in ( 'Softmax','Placeholder')]
[n.name + '=>' + n.op for n in gf.node if n.op in ( 'Softmax','Mul')]

Categories