Failed to load dynamic library 'libtensorflowlite_c.so': dlopen failed: library "libtensorflowlite_c.so" not found - flutter

When I tried to call
/// runs and transforms the data 🤖
this._interpreter.run(input, output);
this._interpreter = await Interpreter.fromAsset('mobilefacenet.tflite',
options: interpreterOptions);
Got this error
Failed to load dynamic library 'libtensorflowlite_c.so': dlopen failed: library "libtensorflowlite_c.so" not found

For Windows users:
Copy all these lines on notepad:
#echo off
setlocal enableextensions
cd %~dp0
set TF_VERSION=2.5
set URL=https://github.com/am15h/tflite_flutter_plugin/releases/download/
set TAG=tf_%TF_VERSION%
set ANDROID_DIR=android\app\src\main\jniLibs\
set ANDROID_LIB=libtensorflowlite_c.so
set ARM_DELEGATE=libtensorflowlite_c_arm_delegate.so
set ARM_64_DELEGATE=libtensorflowlite_c_arm64_delegate.so
set ARM=libtensorflowlite_c_arm.so
set ARM_64=libtensorflowlite_c_arm64.so
set X86=libtensorflowlite_c_x86_delegate.so
set X86_64=libtensorflowlite_c_x86_64_delegate.so
SET /A d = 0
:GETOPT
if /I "%1"=="-d" SET /A d = 1
SETLOCAL
if %d%==1 CALL :Download %ARM_DELEGATE% armeabi-v7a
if %d%==1 CALL :Download %ARM_64_DELEGATE% arm64-v8a
if %d%==0 CALL :Download %ARM% armeabi-v7a
if %d%==0 CALL :Download %ARM_64% arm64-v8a
CALL :Download %X86% x86
CALL :Download %X86_64% x86_64
EXIT /B %ERRORLEVEL%
:Download
curl -L -o %~1 %URL%%TAG%/%~1
mkdir %ANDROID_DIR%%~2\
move /-Y %~1 %ANDROID_DIR%%~2\%ANDROID_LIB%
EXIT /B 0
Save the file as install.bat and put the file in root directory of your project.
Open in explorer and open a command window there.
Type install.bat and press Enter. Use install.bat -d (Windows) instead if you wish to use GpuDelegateV2 and NnApiDelegate.
For Linux/Mac users:
Copy all these lines on notepad
#!/usr/bin/env bash
cd "$(dirname "$(readlink -f "$0")")"
# Available versions
# 2.5, 2.4.1
TF_VERSION=2.5
URL="https://github.com/am15h/tflite_flutter_plugin/releases/download/"
TAG="tf_$TF_VERSION"
ANDROID_DIR="android/app/src/main/jniLibs/"
ANDROID_LIB="libtensorflowlite_c.so"
ARM_DELEGATE="libtensorflowlite_c_arm_delegate.so"
ARM_64_DELEGATE="libtensorflowlite_c_arm64_delegate.so"
ARM="libtensorflowlite_c_arm.so"
ARM_64="libtensorflowlite_c_arm64.so"
X86="libtensorflowlite_c_x86_delegate.so"
X86_64="libtensorflowlite_c_x86_64_delegate.so"
delegate=0
while getopts "d" OPTION
do
case $OPTION in
d) delegate=1;;
esac
done
download () {
wget "${URL}${TAG}/$1" -O "$1"
mkdir -p "${ANDROID_DIR}$2/"
mv $1 "${ANDROID_DIR}$2/${ANDROID_LIB}"
}
if [ ${delegate} -eq 1 ]
then
download ${ARM_DELEGATE} "armeabi-v7a"
download ${ARM_64_DELEGATE} "arm64-v8a"
else
download ${ARM} "armeabi-v7a"
download ${ARM_64} "arm64-v8a"
fi
download ${X86} "x86"
download ${X86_64} "x86_64"
Save the file as install.sh name and put the file in root directory of your project.
Open a command window there.
Type sh install.sh and press Enter. Use sh install.sh -d instead if you wish to use GpuDelegateV2 and NnApiDelegate.

You need to add a file in the root directory in the app found in
tflite_flutter package. tflite_flutter. You can also find it here.
just download the file and place it into the root directory in your app and double click to install the needed information. (For Windows)

I had the same error. Hopefully this is helpful to someone.
After using the install.sh file, that error showed (only on Android, iOS worked fine). But I had changed the wget to curl in the install file and it had downloaded a redirect html page.
The replacement that worked for me was:
# wget "${URL}${TAG}/$1" -O "$1" # Replaced with the below line
curl -L "${URL}${TAG}/$1" -o "$1"
Try to confirm that the files you have downloaded are the correct files. You can inspect these files in <projectdirectory>/android/app/src/main/jniLibs. They should be binary files that begin with ^?ELF, not html files like what I had.

Related

How can I return to the previous directory in windows command prompt?

I often want to return to the previous directory I was just in in cmd.exe, but windows does not have the "cd -" functionality of Unix. Also typing cd ../../.. is a lot of typing.
Is there a faster way to go up several directory levels?
And ideally return back afterwards?
This worked for me in powershell
cd ..
Steps:
pushd . (Keep old folder path on the stack)
cd ..\.. (Move to the folder whare you like to)
popd (Pop it from the stack. Meaning, Come back to the old folder)
On Windows CMD, I got used to using pushd and popd. Before changing directory I use pushd . to put the current directory on the stack, and then I use cd to move elsewhere. You can run pushd as often as you like, each time the specified directory goes on the stack. You can then CD to whatever directory, or directories , that you want. It does not matter how many times you run CD. When ready to return , I use popd to return to whatever directory is on top of the stack. This is suitable for simple use cases and is handy, as long as you remember to push a directory on the stack before using CD.
Run cmd.exe using the /k switch and a starting batch file that invokes doskey to use an enhanced versions of the cd command.
Here is a simple batch file to change directories to the first parameter (%1) passed in, and to remember the initial directory by calling pushd %1.
md_autoruns.cmd:
#echo off
cd %1
pushd %1
title aliases active
cls
%SystemRoot%\System32\doskey.exe /macrofile=c:\tools\aliases
We will also need a small helper batch file to remember the directory changes and to ignore changes to the same directory:
mycd.bat:
#echo off
if '%*'=='' cd & exit /b
if '%*'=='-' (
cd /d %OLDPWD%
set OLDPWD="%cd%"
) else (
cd /d %*
if not errorlevel 1 set OLDPWD="%cd%"
)
And a small aliases file showing what to do to make it all work:
aliases:
cd=C:\tools\mycd.bat $*
cd\=c:\tools\mycd.bat ..
A:=c:\tools\mycd.bat A:
B:=c:\tools\mycd.bat B:
C:=c:\tools\mycd.bat C:
...
Z:=c:\tools\mycd.bat Z:
.=cd
..=c:\tools\mycd.bat ..
...=c:\tools\mycd.bat ..\..
....=c:\tools\mycd.bat ..\..\..
.....=c:\tools\mycd.bat ..\..\..\..
......=c:\tools\mycd.bat ..\..\..\..\..
.......=c:\tools\mycd.bat ..\..\..\..\..\..
........=c:\tools\mycd.bat ..\..\..\..\..\..\..
.........=c:\tools\mycd.bat ..\..\..\..\..\..\..\..
tools=c:\tools\mycd.bat C:\tools
wk=c:\tools\mycd.bat %WORKSPACE%
Now you can go up a directory level by typing ..
Add another . for each level you want to go up.
When you want to go back, type cd - and you will be back where you started.
Aliases to jump to directories like wk or tools (shown above) swiftly take you from location to location, are easy to create, and can really help if you work in the command line frequently.
You could use the command:
cd ..\ -> To go up one level
cd ..\..\ -> To go up two levels
Note the space after cd

wget - if requested file is 0kb or connection timed out then do not save file

I have a script to download file from a siemens PLC and save with date.
set _my_datetime=%date%_%time%
set _my_datetime=%_my_datetime: =_%
set _my_datetime=%_my_datetime::=_%
set _my_datetime=%_my_datetime:/=_%
set _my_datetime=%_my_datetime:.=_%
set _my_datetime=%_my_datetime:,=_%
c:\Progra~2\GnuWin32\bin\wget.exe -t 5 --referer=http://192.yyy.xx.102/Portal/Portal.mwsl?PriNav=FileBrowser http://192.yyy.xx.102/FileBrowser/Download?Path=/DataLogs/Datalog_Yazaki.csv^&RAW --output-document=F:\DataLog_%_my_datetime%.csv --delete-after
And it makes lot of 0kb file if the plc not running.
How do i modify the script to check if it is "0kb" or "no connection" to host then do not save file.
After you do wget try to check the ERRORLEVEL.If its not zero then most probably the command errored out.
set _my_datetime=%date%_%time%
set _my_datetime=%_my_datetime: =_%
set _my_datetime=%_my_datetime::=_%
set _my_datetime=%_my_datetime:/=_%
set _my_datetime=%_my_datetime:.=_%
set _my_datetime=%_my_datetime:,=_%
c:\Progra~2\GnuWin32\bin\wget.exe -t 5 --referer=http://192.yyy.xx.102/Portal/Portal.mwsl?PriNav=FileBrowser http://192.yyy.xx.102/FileBrowser/Download?Path=/DataLogs/Datalog_Yazaki.csv^&RAW --output-document=C:\DataLog_%_my_datetime%.csv --delete-after
if %ERRORLEVEL% NEQ 0 (
echo "Error occurred"
GOTO END
)
:END
REM Exit routine
i solved with a script on linux which is deleting 0kb files.
find . -maxdepth 1 -size 0 -exec rm {} \;

Including some SFTP commands in a Makefile

I use a Makefile to create pdfs of papers I'm working on. I'd also like to use make to upload the latest version to my website, which requires sftp. I though I could do something like this (which words on the command line) but it seems that in make, the EOF is getting ignored i.e., this
website:
sftp -oPort=2222 me#mywebsite.com << EOF
cd papers
put research_paper.pdf
EOF
generates an error message
cd papers
/bin/sh: line 0: cd: papers: No such file or directory
which I think is saying "papers" doesn't exist on your local machine i.e., the 'cd' is being executed locally, not remotely.
Couple of ideas:
use ncftp which every Linux distro as well as brew should have: it remembers 'state' so the cd becomes unnecessary
use scp instead of sftp if possible
write a trivial shell script doing the EOF business and call that
For what it is worth, here is my script to push tarballs to the CRAN winbuilder -- and takes target directory and script as arguments to ncftpput.
#!/bin/bash
function errorexit () {
echo "Error: $1"
exit 1
}
if [ "$#" -lt 1 ]; then
errorexit "Need to specify argument file"
fi
if [ ! -f ${1} ]; then
errorexit "File ${1} not found, aborting."
fi
ncftpput win-builder.r-project.org /R-release ${1}
ncftpput win-builder.r-project.org /R-devel ${1}
I then just do wbput.sh foo_1.2-3.tar.gz and off it goes...
You cannot (normally) put a single command on multiple lines in a Make recipe, so here documents are a no-go. Try this instead:
website: research_paper.pdf
printf 'cd papers\nput $<\n' \
| sftp -oPort=2222 me#mywebsite.com
The target obviously depends on the PDF, so I made it an explicit dependency, as well.

launch sublime text 3 in terminal with zsh

I recently purchased a new MacBook and I am trying to re-configure my system.
The app is inside the Applications folder as 'Sublime Text.app'
I have edited the sublime.plugin.zsh file via other advice I found online to 'Sublime Text 3.app' as well as 'Sublime Text.app' with no luck on either:
elif [[ $('uname') == 'Darwin' ]]; then
local _sublime_darwin_paths > /dev/null 2>&1
_sublime_darwin_paths=(
"/usr/local/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
)
for _sublime_path in $_sublime_darwin_paths; do
if [[ -a $_sublime_path ]]; then
alias subl="'$_sublime_path'"
alias st=subl
break
fi
done
fi
alias stt='st .'
I still get
zsh: command not found: st
I am simply at a loss on where to go next
I had the same problem with zsh and this did the job:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Then you launch a open a file my_file.txt with Sublime:
subl ./my_file.txt
Don't specify any file if you just want to open Sublime. I hope this helps ;)
First, try to first launch the sublime binary manually (interactively) via zsh.
To do that, you'll have to discover where this binary is. There are two practical options here, choose what you are most comfortable with:
Check manually those listed binaries, see which of them exist.
Slightly modify your script to echo something inside your if:
if [[ -a $_sublime_path ]]; then
echo "Sublime found: $_sublime_path"
alias subl="'$_sublime_path'"
alias st=subl
break
fi
After finding the correct one, create the st alias in your .zshrc file:
alias st="/correct/path/to/subl"
If you don't find anything in the first step, then your original script is really not supposed to work.
Just moved to App in mac
Check your current path
echo $PATH
Add a sym link from Sublime App to one of your path. Choose /usr/local/bin for example
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime
Then back to terminal and run sublime. You should be open the sublime through terminal
To setup alias for mac users;
open ~/.zshrc using the below command
vi ~/.zshrc
Add the following alias
alias subl="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'"
run subl . command should work properly.
Official documentation: https://www.sublimetext.com/docs/command_line.html#mac
ZSH
If using Zsh, the default starting with macOS 10.15, the following command will add the bin folder to the PATH environment variable:
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile

Can a Fish script tell what directory it's stored in?

So, I really like Fish - but I need some help with scripting.
and in particular finding the path of the script being run.
Here is the solution for BASH
Getting the source directory of a Bash script from within
Can anyone help me find the equivalent with fish?
status --current-filename will output the path to the currently executing script.
For more information on the status command, you can run man status or see the documentation at http://fishshell.com/docs/current/commands.html#status
In fish shell,
set DIR (cd (dirname (status -f)); and pwd)
is an equivalent to the BASH one liner
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
mentioned in Can a Bash script tell what directory it's stored in?.
NOTE: fish shell will cd into that dir and stay there. Bash will cd but it stays contained in subcommand.
File path
To get the full path of the script, use status --current-filename, or
set FILE (status --current-filename) to declare a variable.
Directory path
To get the full path to the directory the script is stored in, use dirname (status --current-filename), or set DIR (dirname (status --current-filename)) to declare a variable.
The equivalent to this question is the following:
set DIR (dirname (status --current-filename)) is the equivalent
Since readlink -m does not exist on macOS,
DIR=dirname (realpath (status -f))
Works on macOS and Linux at the same time.
This solution also has the benefit to work from an .sh file or even the command line.