Questions about cloth testing

I saw in the group file that there are two frameworks for fabric detection.
Some codes in tensorflow and pytorch are not understood, and I am not sure what baseline is? What kind of submission results are called good?
import tensorflow as tf
import tensorflow.keras.backend as K
from tensorflow.keras.layers import *
from tensorflow.keras.models import *
from tensorflow.keras.optimizers import *
from tensorflow.keras.callbacks import *
from tensorflow.keras.layers import Input
import numpy as np
import os
import zipfile

def RMSE(y_true, y_pred):
return tf.sqrt(tf.reduce_mean(tf.square(y_true - y_pred)))

def build_model(): inp
= Input(shape=(12,24,72,4)) #What kind of four-dimensional data is input here?

x_4    = Dense(1, activation='relu')(inp)   
x_3    = Dense(1, activation='relu')(tf.reshape(x_4,[-1,12,24,72]))
x_2    = Dense(1, activation='relu')(tf.reshape(x_3,[-1,12,24]))
x_1    = Dense(1, activation='relu')(tf.reshape(x_2,[-1,12]))
 
x = Dense(64, activation='relu')(x_1)  #这里全链接层后面1,64代表什么?
x = Dropout(0.25)(x) 
x = Dense(32, activation='relu')(x)   
x = Dropout(0.25)(x)  #这里群里面问了代表丢弃的概率
output = Dense(24, activation='linear')(x)   
model  = Model(inputs=inp, outputs=output)

adam = tf.optimizers.Adam(lr=1e-3,beta_1=0.99,beta_2 = 0.99) 
model.compile(optimizer=adam, loss=RMSE)

return model 

model = build_model()

model.load_weights(’./user_data/model_data/model_mlp_baseline.h5’)

model.load_weights('./model_mlp_baseline.h5') #What weight is not understood here? What does the file h5 mean?

test_path = ‘./tcdata/enso_round1_test_20210201/’

test_path ='./anno_train.json' #Why are the upper and lower paths different here?

1. Test data reading

files = os.listdir(test_path)

files = os.listdir(dict(test_path))

test_feas_dict = {}
for file in files:
test_feas_dict[file] = np.load(test_path + file)

2. Outcome prediction

test_predicts_dict = {}
for file_name,val in test_feas_dict.items():
test_predicts_dict[file_name] = model.predict(val).reshape(-1,)

test_predicts_dict[file_name] = model.predict(val.reshape([-1,12])[0,:])

3. Store prediction results

for file_name,val in test_predicts_dict.items():
np.save(’./result/’ + file_name,val)

#打包目录为zip文件(未压缩)
def make_zip(source_dir=’./result/’, output_filename = ‘result.zip’):
zipf = zipfile.ZipFile(output_filename, ‘w’)
pre_len = len(os.path.dirname(source_dir))
source_dirs = os.walk(source_dir)
print(source_dirs)
for parent, dirnames, filenames in source_dirs:
print(parent, dirnames)
for filename in filenames:
if ‘.npy’ not in filename:
continue
pathfile = os.path.join(parent, filename)
arcname = pathfile[pre_len:].strip(os.path.sep) #相对路径
zipf.write(pathfile, arcname)
zipf.close()
make_zip()

The program does not run through

Guess you like

Origin blog.csdn.net/m0_49978528/article/details/113926153