Tested the documentation example of nn.CrossEntropyLoss. It doesn't seem to work.
loss = nn.CrossEntropyLoss()
input = torch.randn(3, 5, requires_grad=True)
target = torch.randn(3, 5).softmax(dim=1)
output = loss(input, target)
print(output)
error:
RuntimeError: 1D target tensor expected, multi-target not supported
You might need to upgrade your torch version.
pip install torch --upgrade
Related
I have been trying to make an inference using the Yolov4 Darknet model I trained, and whenever I try to run the Command in Powershell, all It does is print out Cuda Version and OpenCv Version. If anybody has experienced this or knows a solution that would be amazing.
You will have to specify the input file/video as the last cmd line argument to perform inference on that particular file/video.
For example:
input image: darknet.exe detector test cfg/coco.data yolov4.cfg yolov4.weights -ext_output dog.jpg
video: darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -ext_output test.mp4
WebCam 0: darknet.exe detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -c 0
I'm trying to run this elephas tutorial on Colab.
I prepared the environment with
!apt-get install openjdk-8-jdk-headless -qq > /dev/null
!wget -q https://downloads.apache.org/spark/spark-2.4.6/spark-2.4.6-bin-hadoop2.7.tgz
!tar xf spark-2.4.6-bin-hadoop2.7.tgz
!pip install -q findspark
import os
os.environ["JAVA_HOME"] = "/usr/lib/jvm/java-8-openjdk-amd64"
os.environ["SPARK_HOME"] = "/content/spark-2.4.6-bin-hadoop2.7"
import findspark
findspark.init("spark-2.4.6-bin-hadoop2.7")
!pip install elephas
When I fit the model
pipeline = Pipeline(stages=[estimator])
fitted_pipeline = pipeline.fit(df)
I get the following error message
>>> Fit model
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-11-6d2ae7604dd2> in <module>()
1 # Fitting a model returns a Transformer
2 pipeline = Pipeline(stages=[estimator])
----> 3 fitted_pipeline = pipeline.fit(df)
11 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/optimizers.py in get(identifier)
901 else:
902 raise ValueError(
--> 903 'Could not interpret optimizer identifier: {}'.format(identifier))
ValueError: Could not interpret optimizer identifier: 1e-06
As you can see, the error relates to decay (decay=1e-6). Anyway, I still get the same error even when I change this value.
sgd = optimizers.SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
sgd_conf = optimizers.serialize(sgd)
Any ideas?
This may have had to do with an incompatibility if you were working with Tensorflow 2.0 API. I would recommend retrying with the latest release: https://github.com/danielenricocahall/elephas/releases/tag/1.0.0 which now contains support for Tensorflow 2.1.x and Tensorflow 2.3.x.
I am new to OpenCV and Google Colab. I have been working on a project that requires me to take the real-time image frames from the webcam and process it. But the problem is from the below code the 'frame' always returns a 'None' type and my webcam does not seem to switch on. But using the example code from Colab to capture images works fine:
How to use cap = cv2.VideoCapture(0) in Google Colab
Here is the code that fails:
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
---> 19 frame = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
error: OpenCV(3.4.3) /io/opencv/modules/imgproc/src/color.cpp:181: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
try replace the first line with
frame = cv2.imread('your_image.png',0)
If it works, then the high chance is your camera issue.
There could be multiple reason. try
sudo apt-get install ffmpeg
sudo apt-get install cheese
cheese
to see if you can get video feed in ubuntu. If can, then its opencv config issue. if cannot then its either driver or hardware issue.
If its driver issue. follow https://help.ubuntu.com/community/Webcam to driver
If hardware broke down, not much you can do software
I am seeing a strange problem with z3py on Mac, was wondering if anyone has seen this before:
$ cat bug.py
from z3 import *
x = Int('x')
s = Solver()
s.add(x > 5)
print(s.check())
print(s.model())
$ python bug.py
sat
[x = ]
The value of x is missing from the model. I tried both master and unstable branches with the same result. However, z3 itself does give the correct model if run on a similar .smt2 file. My configuration is Mac OSX 10.6.8, Python 2.7.4.
The problem is very specific for my setup, but maybe someone will run into it as well: the root cause is that a wrong version of libgomp was picked up by the dynamic loader -- i.e. the versions used to compile and to run do not match.
Here is a more severe manifestation of this issue:
$ python
Python 2.7.4 (default, May 9 2013, 18:51:46)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from z3 import *
>>> IntVal(1)
>>>
The numeric value is not printed, i.e. the correct output is
>>> IntVal(1)
1
>>>
Setting DYLD_LIBRARY_PATH to point to the correct version of the library fixes the issue.
I don't see any problems with Z3 4.1 and Python 2.7.2 on my Mac OSX 10.8.3. I wonder if it's some sort of terminal issue that eats the characters for whatever reason. What do you see if you redirect the output to a file? (i.e., try "python bug.py > out". Does the contents of the file "out" look OK?)
Has anyone tried to install opencv for python3?. As stated here http://opencv.willowgarage.com/wiki/InstallGuide its support status is unknown. So I want to try it:
I have downloaded the sources for OpenCV-2.3.1. But cmake reports.
-- Python interpreter: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 -B (ver
3.2)
-- Python numpy: NO (Python wrappers will not be generated)
I do have numpy (version 1.6.0) installed in python3 but cmake does not find it. I am using Mac OSX 10.6 Any ideas?
Update
I just saw one more thing of the cmake output that might be helpful
-- Found PythonInterp: /Library/Frameworks/Python.framework/Versions/3.2/bin/python3 (found
version "3.2")
-- Found PythonLibs: /usr/lib/libpython2.6.dylib File "", line 1
from distutils.sysconfig import *; print get_python_lib()
^
SyntaxError: invalid syntax File "", line 1
import os; os.environ['DISTUTILS_USE_SDK']='1'; import numpy.distutils; print
numpy.distutils.misc_util.get_numpy_include_dirs()[0]
^
SyntaxError: invalid syntax File "", line 1
import sphinx; print sphinx.__version__
^ SyntaxError: invalid syntax
Notice that it found 3.2 but then libpython2.6 ??
Any ideas?
At the moment OpenCV supports Python 2.x only. OpenCV (including OpenCV 2.4) does not compiles with Python 3.x.
Python3 support is already in wishlist for future versions of OpenCV. But currently there are no activities in this direction and you are welcome to create and contribute a patch resolving the compatibility issues.
Use the pip application.
On ubuntu:
sudo apt install python3-pip
and so, on command line:
pip3 install --upgrade pip
pip3 install opencv-python
I got the thing to at least build and install. It can load the cv2 module just fine. Haven't tested too much though.
Details:
https://stackoverflow.com/a/21212023/3075814