Simple Running A Complicated Python Script

Let’s say you got a complicated script that need some libraries to make it Run well

import tensorflow as tf
import cv2.cv2 as cv
import pathlib
# Load TFLite model and allocate tensors.
interpreter = tf.lite.Interpreter(model_path="model.tflite")
# Get input and output tensors.
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# input details
# output details
for file in pathlib.Path("folder").iterdir():

# read and resize the image
img = cv.imread(r"{}".format(file.resolve()))
new_img = cv.resize(img, (224, 224))

interpreter.set_tensor(input_details[0]['index'], [new_img])
output_data = interpreter.get_tensor(output_details[0]['index'])
if (output_data[0][0] > 200):
print("file {} -> indosiar_ads".format(file.stem))
elif (output_data[0][1] > 200):
print("file {} -> indosiar".format(file.stem))
elif (output_data[0][2] > 200):
print("file {} -> sctv".format(file.stem))
elif (output_data[0][3] > 200):
print("file {} -> sctv_ads".format(file.stem))
print("file {} -> unknown".format(file.stem))

install python3

sudo apt-get install python3

install pip

sudo apt install python3-pip

Don’t forget to update

pip install --upgrade pip

noted : if you just want to experiment the script, better you use virtual environment or jupyter notebook

install the required dependencies

pip3 install tensorflow
pip3 install pathlib
pip3 install opencv-python

Running the script





Still believe, can change the world with code..

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Designing OneLogin for Scale and Reliability — Part 1: Login Clusters

Auction Swap Boosting Airdrop Event

Azure Function Github to Slack Pipeline

Avoid cascading if-else in Kotlin

If-else hell

Data Types in SQL

Syntax support for tests and invariants — Pythonic?

Sharing State Between Cucumber Step Definitions Using Java and Spring

Google Phone Interview

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
ade sueb

ade sueb

Still believe, can change the world with code..

More from Medium

Python: Core data types

4 CLI Commands for Data Munging

Make python to wish your friends a happy birthday on their birthday nights

Philips Hue with python

Python philips hue