I'm using Tensorflow 1.9.0 version which is built with AVX support, but when I'm packaging the project into an EXE and testing on another machine it crashes due to not having AVX support on this machine. so I revert back to Tensorflow 1.5 and it worked fine.
Now the question is can I switch to the desired Tensorflow version after detecting the AVX support in machine dynamically (on run time).
I don't know how to switch version so didn't try but I'm detecting the AVX support. like this
>>> import cpuinfo
>>> cpuinfo.get_cpu_info()
{'python_version': '3.6.5.final.0 (64 bit)',
'cpuinfo_version': [5, 0, 0], 'arch': 'X86_64', 'bits': 64, 'count': 4, 'raw_arch_string': 'AMD64', 'vendor_id': 'GenuineIntel',
'brand': 'Intel(R) Core(TM) i3-2350M CPU # 2.30GHz', 'hz_advertised': '2.3000 GHz', 'hz_actual': '1.6000 GHz', 'hz_advertised_raw': [2300000000, 0], 'hz_actual_raw': [1600000000, 0], 'l2_cache_size': '512 KB', 'stepping': 7, 'model': 42, 'family': 6, 'l3_cache_size': '3072 KB',
'flags': ['acpi', 'apic', 'avx', 'clflush', 'cmov', 'cx16', 'cx8', 'de', 'ds_cpl', 'dtes64', 'dts', 'est', 'fpu', 'fxsr', 'ht', 'ia64', 'lahf_lm', 'mca', 'mce', 'mmx', 'monitor', 'msr', 'mtrr', 'osxsave', 'pae', 'pat', 'pbe', 'pcid', 'pclmulqdq', 'pdcm', 'pge', 'pni', 'popcnt', 'pse', 'pse36', 'sep', 'serial', 'ss', 'sse', 'sse2', 'sse4_1', 'sse4_2', 'ssse3', 'tm', 'tm2', 'tsc', 'tscdeadline', 'vme', 'vmx', 'x2apic', 'xsave', 'xtpr'],
'l2_cache_line_size': 6, 'l2_cache_associativity': '0x100', 'extended_model': 2}
I want to package both (AVX support and unsupported) versions in same EXE and use it according to the needs. Any other suggestions are welcomed.
Thanks
Your question contains part of the answer. From cpuinfo.get_cpu_info(), you will get whether AVX is supported or not(mentioned in 'flags'). Accordingly, you can install the required packages inside the python code itself( Refer Installing python module within code for details).
Alternatively, you can do the same thing from terminal. grep flags /proc/cpuinfo will give you flags supported. Depending on if avx is there or not, create a script to install tensorflow of the appropriate version
Related
i git yolov7(https://github.com/WongKinYiu) with yolov7.pt and try to run
detect.py(i just want to run the example). it seems to be normal. but the output image has no mask.Why?
here is my code and log:
(PyTorch) E:\yolov7>python detect.py --weights yolov7.pt --source inference\images\bus.jpg
Namespace(weights=['yolov7.pt'], source='inference\\images\\bus.jpg', img_size=640, conf_thres=0.25, iou_thres=0.45, device='', view_img=False, save_txt=False, save_conf=False, nosave=False, classes=None, agnostic_nms=False, augment=False, update=False, project='runs/detect', name='exp', exist_ok=False, no_trace=False)
YOLOR v0.1-103-g6ded32c torch 1.11.0 CUDA:0 (NVIDIA GeForce GTX 1650, 4095.6875MB)
Fusing layers...
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
RepConv.fuse_repvgg_block
Model Summary: 306 layers, 36905341 parameters, 6652669 gradients
Convert model to Traced-model...
traced_script_module saved!
model is traced!
E:\anaconda\envs\PyTorch\lib\site-packages\torch\functional.py:568: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at C:\cb\pytorch_1000000000000\work\aten\src\ATen\native\TensorShape.cpp:2228.)
return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]
Done. (151.6ms) Inference, (9.3ms) NMS
The image with the result is saved in: runs\detect\exp4\bus.jpg
Done. (3.713s)
and here is my result:output image
You set the argument classes=None.
The classes variable refers to a list of classes, where you define the index of the entities saved inside the weights you are referencing for the inference.
From detect.py:
parser.add_argument('--classes', nargs='+', type=int, help='filter by class: --class 0, or --class 0 2 3')
Since you told the model to check for zero classes, the model itself will not report anything.
I was also facing this issue. After downgrading cuda version to 10.2 my problem was solved. I used Cuda 10.2 with PyTorch 1.10.0 via pip installation. I hope it helps you too.
pip3 install torch==1.10.0+cu102 torchvision==0.11.1+cu102 torchaudio===0.10.0+cu102 -f https://download.pytorch.org/whl/cu102/torch_stable.html
Source of the answer: link
Since when you are working with GPU, It allows half precision by default, which you can change by editing your detect.py file.
Go to detect.py file and not exactly sure but on line 31, you will see this line of code:
half = device.type != 'cpu' # half precision only supported on CUDA
Replace that line with
half = False
and then save default.py file.
Now when you are using your detection command, make sure to use --device 0 that indicates your GPU must be utilize for detection.
python detect.py --weights yolov7.pt --device 0 --source inference\images\bus.jpg
We have finetuned our BERT model for text2text generation. It is working fine on the Jupyter notebook. But when I use the same trained model on another server of Ubuntu, then it shows the issue. This is my first post, so please bear with me. The issue I'm facing is that when I generate output on small sentences, it works fine. But on long sentences, it shows the following error:
At most 4 tokens in tensor([ 2, 2, 2, 2, 44763, 44763, 2, 44763]) can be equal to eos_token_id: 2. Make sure tensor([ 2, 2, 2, 2, 44763, 44763, 2, 44763]) are corrected.
My output generation code is:
from simpletransformers.seq2seq import Seq2SeqModel
#logging.basicConfig(level=logging.INFO)
#transformers_logger = logging.getLogger("transformers")
#transformers_logger.setLevel(logging.ERROR)
model = Seq2SeqModel(
encoder_decoder_type="bart", encoder_decoder_name="PATHOFMODEL",use_cuda=False,
)
while True:
original = input("Enter text to paraphrase: ")
to_predict = [original]
preds = model.predict(to_predict)
print("---------------------------------------------------------")
print(original)
print()
print("Predictions >>>")
for pred in preds[0]:
print(pred)
print("---------------------------------------------------------")
print()
You can check your TensorFlow version in your jupyter notebook and verify it on your Ubuntu server. If it's the same, there should be no error.
Firstly uninstall the tensorflow.
pip3 uninstall tensorflow
and then install any old version. Like in the case of version 2.2.0, then install 2.2.0 version using below command.
pip3 install tensorflow==2.2.0
It should work now.
Hi, I have two GPUs and sometimes I want to run one script on GPU:0 and the other one on GPU:1. the question is how can I execute a python script on a specific GPU, or how to bind script execution to a particular GPU. Looking ahead I'll say what I know about with tf.device('/device:GPU:1'):
I thought I can solve my issue using tf.config.experimental.set_visible_devices but I was wrong. The plan was simple: at the top of the code, I planned to set up the required GPU. And then, as I thought, the script will run on that GPU which I made visible. But I was wrong - see the code below. In my case when I run the script I got an error:
TensorFlow device (GPU:0) is being mapped to multiple CUDA devices (1 now, and 0 previously),
which is not supported. This may be the result of providing different GPU configurations
(ConfigProto.gpu_options, for example different visible_device_list) when creating multiple
Sessions in the same process. This is not currently supported, see https://github.com/tensorflow/tensorflow/issues/19083
__
import tensorflow as tf
def work():
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
for i in range(100000):
c = tf.matmul(a, b)
def main():
print(tf.__version__)
tf.config.set_soft_device_placement(False)
tf.debugging.set_log_device_placement(True)
gpus = tf.config.experimental.list_physical_devices('GPU')
if gpus:
try:
print(f'set visible GPU device as {gpus[1]}')
tf.config.experimental.set_visible_devices(gpus[1], 'GPU')
except RuntimeError as e:
print(e)
device_name = tf.test.gpu_device_name()
print(device_name)
with tf.device('/device:GPU:1'):
work()
if __name__ == "__main__":
main()
I believe I'm not the first person who meets with this issue - could somebody share the solution?
as turn it out the casket opened simple - here is what I find out. When you have 2 GPU and call tf.config.experimental.set_visible_devices(gpus[1], 'GPU') they're only one GPU will be available for your script Device:1 (In my example) . BUT... IT IS IMPORTANT - the name(number) of this device will be Device:0 instead of Device:1 as it can be expected. And here is the reason: the system re-enumerates all available for your script GPUs beginning from the scratch - it means the first name of your device will be started from 0 again, despite your real device that has the name Device:1 - thus the available in your script device will have name Device:0, not Device:1.
I hope this can help someone like me.
System information
custom code: no, it is the one in https://www.tensorflow.org/get_started/estimator
system: Apple
OS: Mac OsX 10.13
TensorFlow version: 1.3.0
Python version: 3.6.3
GPU model: AMD FirePro D700 (actually, two such GPUs)
Describe the problem
Dear all,
I am running the simple iris program:
https://www.tensorflow.org/get_started/estimator
under python 3.6.3 and tensorflow 1.3.0.
The program executes correctly, apart from the very last part, i.e. the one related to the confusion matrix.
In fact, the result I get for the confusion matrix is:
New Samples, Class Predictions: [array([b'1'], dtype=object), array([b'2'], dtype=object)]
rather than the expected output:
New Samples, Class Predictions: [1 2]
Has anything about confusion matrix changed in the latest release?
If so, how should I modify that part of the code?
Thank you very much for your help!
Best regards
Ivan
Source code / logs
https://www.tensorflow.org/get_started/estimator
This looks like a numpy issue. array([b'1'], dtype=object) is one way numpy represents the string '1'.
For the script:
import tensorflow as tf;
class ZeroOutTest(tf.test.TestCase):
def testZeroOut(self):
zero_out_module = tf.load_op_library('/Users/sahilsingla/tensorflow/bazel-bin/tensorflow/core/user_ops/zero_out.so')
with self.test_session():
result = zero_out_module.zero_out([5, 4, 3, 2, 1])
value = result.eval()
self.assertAllEqual(value, [5, 0, 0, 0, 0])
if name == "main":
tf.test.main()
This is the same script given in tensorflow's documentation in "creating a new op", https://www.tensorflow.org/versions/r0.11/how_tos/adding_an_op/index.html
When I run: bazel test tensorflow/python/kernel_tests:zero_out_op_test
I get the error: tensorflow.python.framework.errors.NotFoundError: dlopen(zero_out.so, 6): image not found.
The funny thing is this does load when I do :
python -c "import tensorflow as tf;
zero_out_module = tf.load_op_library('/Users/sahilsingla/tensorflow/bazel-bin/tensorflow/core/user_ops/zero_out.so')"
but doesn't load with bazel test.
Can anyone please suggest what I am doing wrong? How can this error be removed?
For those facing the same problem, I will suggest try building using
bazel build -c opt //tensorflow/g3doc/how_tos/adding_an_op:zero_out_op_kernel_1.so
bazel test //tensorflow/g3doc/how_tos/adding_an_op:zero_out_1_test
instead of how it is given in the tensorflow documentation.
You will get a good idea how to make it work.