问题描述
我在编码等方面是全新的,但对于我的 uni 项目,我需要此代码或类似的代码! 我已经复制了这段代码,但这部分:
from image.prediction.Custom import ModelTraining,CustomImagePrediction
给我这个错误:
ModuleNotFoundError: No module named 'image.prediction'
这是我的完整代码:
>
>
> from io import open import requests import shutil from zipfile import
> ZipFile from tensorflow.keras.applications.resnet50 import
> preprocess_input,decode_predictions
>
> from image.prediction.Custom import ModelTraining,> CustomImagePrediction import os
>
> execution_path = os.getcwd()
>
> SOURCE_PATH =
> "https://github.com/OlafenwaMoses/Traffic-Net/releases/download/1.0/trafficnet_dataset_v1.zip"
> FILE_DIR = os.path.join(execution_path,"trafficnet_dataset_v1.zip")
> DATASET_DIR = os.path.join(execution_path,> "trafficnet_dataset_v1.zip")
>
>
> def download_traffic_net():
> if (os.path.exists(FILE_DIR) == False):
> print("Downloading trafficnet_dataset_v1.zip")
> data = requests.get(SOURCE_PATH,> stream=True)
>
> with open(FILE_DIR,"wb") as file:
> shutil.copyfileobj(data.raw,file)
> del data
>
> extract = ZipFile(FILE_DIR)
> extract.extractall(execution_path)
> extract.close()
>
>
> def train_traffic_net():
> download_traffic_net()
>
> trainer = ModelTraining()
> trainer.setModelTypeAsresnet()
> trainer.setDataDirectory("trafficnet_dataset_v1")
> trainer.trainModel(num_objects=4,num_experiments=200,batch_size=32,save_full_model=True,enhance_data=True)
>
> def run_predict():
> predictor = CustomImagePrediction()
> predictor.setModelPath(model_path="trafficnet_resnet_model_ex-055_acc-0.913750.h5")
> predictor.setJsonPath(model_json="model_class.json")
> predictor.loadFullModel(num_objects=4)
>
> predictions,probabilities = predictor.predictimage(image_input="images/1.jpg",result_count=4)
> for prediction,probability in zip(predictions,probabilities):
> print(prediction," : ",probability)
>
> #Un-comment the line below to train your model
> #train_traffic_net()
>
> #Un-comment the line below to run predictions run_predict()
当然,我需要告诉你我正在使用 GOOGLE COALB!可能 st 尚未安装在 colab 上,或者 st 的版本是否旧! 非常感谢您的帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)