Mp4 audio: FileNotFoundError: [WinError 2] The system cannot find the file specified - mp4

This is weird.Following is code sample
from pydub.utils import mediainfo
info = mediainfo("fawad.mp4")
print(info['sample_rate'])
If I ls

Related

getting unicode decode error while trying to load pre-trained model using torch.load(PATH)

Trying to load a ResNet 18 pre-trained model using the torch.load(PATH) but getting Unicode decode error please help.
Traceback (most recent call last):
File "main.py", line 312, in <module>
main()
File "main.py", line 138, in main
checkpoint = torch.load(args.resume)
File "F:\InsSoft\Anaconda\lib\site-packages\torch\serialization.py", line 593, in load
return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
File "F:\InsSoft\Anaconda\lib\site-packages\torch\serialization.py", line 773, in _legacy_load
result = unpickler.load()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbe in position 2: invalid start byte
This error hits whenever the model is pretrained on torch version < 0.4 but using torch version > 0.4 for testing / resuming.
so use checkpoint = torch.load(args.resume,encoding='latin1')

ConnectionRefusedError: [Errno 111] Connection refused - MQTT

I am very new to socket and communication using MQTT. Already spent hours but dont know what is wrong. Kindly help me to fix this error.
I am using the below code,
import socket
import json
from random import randint
from inference import Network
import paho.mqtt.client as mqtt
HOSTNAME = socket.gethostname()
IPADDRESS = socket.gethostbyname(HOSTNAME)
MQTT_HOST = IPADDRESS
MQTT_PORT = 1883 ### TODO: Set the Port for MQTT
MQTT_KEEPALIVE_INTERVAL = 60
client = mqtt.Client()
client.connect(MQTT_HOST,MQTT_PORT,MQTT_KEEPALIVE_INTERVAL)
And the error and traceback is shown below,
(venv) root#119d16139409:/home/workspace# python app.py | ffmpeg -v warning -f rawvideo -pixel_format bgr24 -video_size 1280x720 -framerate 24 -i - http://0.0.0.0:3004/fac.ffm
Traceback (most recent call last):
File "app.py", line 145, in <module>
main()
File "app.py", line 141, in main
infer_on_video(args, model)
File "app.py", line 74, in infer_on_video
client.connect(MQTT_HOST,MQTT_PORT,MQTT_KEEPALIVE_INTERVAL)
File "/opt/intel/openvino_2019.3.376/deployment_tools/model_optimizer/venv/lib/python3.5/site-packages/paho/mqtt/client.py", line 937, in connect
return self.reconnect()
File "/opt/intel/openvino_2019.3.376/deployment_tools/model_optimizer/venv/lib/python3.5/site-packages/paho/mqtt/client.py", line 1071, in reconnect
sock = self._create_socket_connection()
File "/opt/intel/openvino_2019.3.376/deployment_tools/model_optimizer/venv/lib/python3.5/site-packages/paho/mqtt/client.py", line 3522, in _create_socket_connection
return socket.create_connection(addr, source_address=source, timeout=self._keepalive)
File "/usr/lib/python3.5/socket.py", line 711, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

How to use pillow library to access image files in sub-directories recursively?

I want to crop and resize multiple images in many sub-directories. The code works if the images are in the same directory, but fails to read from other directories.
I have tried using os.walk() module. It successfully iterate the files from all subdirectories, but the pillow's Image.open() function fails to access the images and thereby displaying error: "image.." not found.
import os
from PIL import Image
for dirpath, dirnames, files in os.walk('.'):
for filename in files:
t = filename.split(".")
ext = t[-1]
if ext in ["jpg"]:
print(filename)
coords = (500, 250, 810,720)
image_obj = Image.open(filename)
cropped_image = image_obj.crop(coords)
resized_image =cropped_image.resize([227,227])
# name = "./data2" + str(i) +".jpg"
resized_image.save("new" + filename)
I expect the code to recursively crop and resize the images in all the sub-directories. The following error occurred.
frame0.jpg
Traceback (most recent call last):
File "........./data2/cropitall.py", line 18, in <module>
image_obj = Image.open(filename) #path of image to be cropped
File "C:\Python36\lib\site-packages\PIL\Image.py", line 2652, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'frame0.jpg'
Process finished with exit code 1
To open the image you need the entire path to the file, not just file name.
Instead of
image_obj = Image.open(filename)
do
path = os.path.join(dirpath, filename)
image_obj = Image.open(path)

Python subprocess.check_output()

mystring = subprocess.check_output(["sudo iwlist wlan0 scan"], universal_newlines=True)
word = 'Devsign2G'
print (mystring)
print (word)
if word in str(mystring):
print ('success')
-error message-
Traceback (most recent call last):
File "test.py", line 52, in
mystring = subprocess.check_output(["sudo iwlist wlan0 scan"], universal_newlines=True)
File "/usr/lib/python2.7/subprocess.py", line 212, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 390, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1024, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
what is the problem?
what is the problem?
The OSError: [Errno 2] No such file or directory refers to the subprocess command which is to be executed.
The program arguments must be passed individually in the sequence, so change
["sudo iwlist wlan0 scan"]
to
["sudo", "iwlist", "wlan0", "scan"]
It looks like your code is using a file called "subprocess" located here: /usr/lib/python2.7/subprocess.py
But the file or directory isn't there. You can change the dir or put the file in the correct folder.
If it's an packaged. Did you install the package with pip or sth? Is it imported?

PyPDF2.PdfFileReader hangs indefinitely

I'm trying to read this pdf file (https://www.accessdata.fda.gov/cdrh_docs/pdf14/K141693.pdf) and am following these suggestions from SO
Opening pdf urls with pyPdf
I have actually downloaded the file locally and am running the following code
import PyPDF2
pdf_file = open("K141693.pdf")
pdf_read = PyPDF2.PdfFileReader(pdf_file)
but my code hangs indefinitely. I'm running Python 2.7 and here is the stacktrace.
Traceback (most recent call last):
File "", line 1, in
runfile('C:/PoC/pdf_reader.py', wdir='C:/PoC')
File
"C:\ProgramData\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py",
line 880, in runfile
execfile(filename, namespace)
File
"C:\ProgramData\Anaconda2\lib\site-packages\spyder\utils\site\sitecustomize.py",
line 87, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "C:/PoC/pdf_reader.py", line 13, in
pdf_read = PyPDF2.PdfFileReader(pdf_file)
File "C:\ProgramData\Anaconda2\lib\site-packages\PyPDF2\pdf.py",
line 1084, in init
self.read(stream)
File "C:\ProgramData\Anaconda2\lib\site-packages\PyPDF2\pdf.py",
line 1697, in read
line = self.readNextEndLine(stream)
File "C:\ProgramData\Anaconda2\lib\site-packages\PyPDF2\pdf.py",
line 1938, in readNextEndLine
x = stream.read(1)
KeyboardInterrupt
I came across another post here PyPDF2 hangs on processing but that too doesn't have a response.
You need to parse the file in binary ('rb') mode. (This works in Python 3:)
import PyPDF2
pdf_file = open("K141693.pdf", "rb")
read_pdf = PyPDF2.PdfFileReader(pdf_file)