多类多标签简单模型

我已经工作了几个星期才能完成一个项目。该项目看起来很简单,但是有很多活动内容。所以 -创建一个具有4个输入图像的简单cnn模型。图像是树木。图像是树的树干,树枝,叶子和树的根。 -有8种不同的树木。 -目标为模型提供了四张图像,并让模型检测出它是哪棵树。 -我必须从Google图片创建原始数据(搜索) 当我为一个学校项目解决这个问题时,我在努力为热标签和多班制图像预处理。然后确保我的模型架构正确。

# import the necessary packages
from keras.models import Sequential
from keras.layers.normalization import BatchNormalization
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.layers.core import activation
from keras.layers.core import Dropout
from keras.layers.core import Dense
from keras.layers import flatten
from keras.layers import Input
from keras.models import Model
from keras.layers import Dense,LSTM,concatenate,Input,flatten

# define four inputs ( Different photos of trees)
inputA = Input(shape=(308,308,1)) # Trunk 
inputB = Input(shape=(308,1)) # Branch
inputC = Input(shape=(308,1)) # Leafs
inputD = Input(shape=(308,1)) # Roots
 
# the first branch operates on the first input
a = Conv2D(16,(2,2),activation='relu')(inputA)
a = Conv2D(16,activation='relu')(a)
a = Model(inputs=inputA,outputs=a)
 
# the second branch opreates on the second input
b = Conv2D(16,activation='relu')(inputB)
b = Conv2D(16,activation='relu')(b)
b = Model(inputs=inputB,outputs=b)

# the third branch opreates on the third input
c = Conv2D(16,activation='relu')(inputC)
c = Conv2D(16,activation='relu')(c)
c = Model(inputs=inputC,outputs=c)

# the fourth branch opreates on the fourth input
d = Conv2D(16,activation='relu')(inputD)
d = Conv2D(16,activation='relu')(d)
d = Model(inputs=inputD,outputs=d)
 
# combine the output of the four branches
combined = concatenate([a.output,b.output,c.output,d.output])
 
# apply a FC layer and then a regression prediction on the
# combined outputs
z = Dense(128,activation="relu")(combined)
z = Dense(4,activation="softmax")(z)
 
# our model will accept the inputs of the four branches and then output a single value
model = Model(inputs=[a.input,b.input,c.input,d.input],outputs=z)
model.summary()

model.compile(loss='categorical_crossentropy',optimizer="adam",metrics=['accuracy'])

这就是我一直试图对预处理数据进行热标签的方式。

from tqdm import tqdm
import tensorflow as tf
import matplotlib.pyplot as plt
%matplotlib inline

train_data = ""
test_data = ""

def one_hot_label(img):
	label = img.split(".")[0]
	if label == "Trunk";
		ohl = np.array([1,0])
	elif label == "Branch":
		ohl = np.array([0,1,0])
  elif label == "Leaf":
		ohl = np.array([0,0])
  elif label == "Root":
		ohl = np.array([0,1])  
	return ohl
def train_data_with_label();
	train_images = []
	for i in tqdm(os.listdir(train_data)):
		path = os.path.join(train_data,i)
		img = cv2.imread(path,cv2.IMREAD_COLOR)
		img = cv2.resize(img,(308,308))
		train_images.append([np.array(img),one_hot_label(i)])
	shuffle(train_images)
	return train_images

def test_data_with_label();
	test_images = []
	for i in tqdm(os.listdir(test_data)):
		path = os.path.join(test_data,308))
		test_images.append([np.array(img),one_hot_label(i)])
	shuffle(test_images)
	return test_images	

这是一个巨大的职位。我知道我一团糟,真的很挣扎。当您运行数据时,其准确性是如此之低,我知道这是错误的。 (约18%) 如果有人可以帮助!讨好。即使方向是有帮助的,也不必是确切的答案。 我对此网站及其上的人员表示感谢。

谢谢 Noob Coder Dyl

wwtt_007 回答:多类多标签简单模型

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2896738.html

大家都在问