network_name=args.network_name, checkpoint_path=args.checkpoint, batch_size=args.batch_size, num_classes=args.num_classes, preproc_func_name=args.preproc_func, preproc_threads=args.num_preproc_threads) # Print the network summary, use these layer names for feature extraction #feature_extractor.print_network_summary() # Feature extraction example using a filename queue to feed images feature_dataset = feature_extraction_queue(feature_extractor, args.image_path, layer_names, args.batch_size, args.num_classes) # print(type(feature_dataset)) # for i in feature_dataset: # print(i) data = feature_dataset['resnet_v2_101/logits'] data = np.reshape(data, [data.shape[0], data.shape[3]]) np.save(args.out_file, data) # Write features to disk as HDF5 file utils.write_hdf5('features.h5', layer_names, feature_dataset) print("Successfully written features to: {}".format(args.out_file)) # Close the threads and close session. feature_extractor.close() print("Finished.")
label3 = label2.split('_') # Get the features for this label. temp = features[index_label] temp0 = np.append(temp, int(label3[0]) - 1) # category temp1 = np.append(temp0, int(label3[1]) - 1) # object class temp2 = np.append(temp1, label3[2]) # session temp3 = np.append(temp2, label3[3][:-4]) # image id within the object class features_array[index_label] = temp3 feature_dataset[layer_names[0]] = features_array # End: Modifications (Vadym Gryshchuk). # Write features to disk as HDF5 file utils.write_hdf5(args.out_file, layer_names, feature_dataset) print("Successfully written features to: {}".format(args.out_file)) # Close the threads and close session. feature_extractor.close() print("Finished.") # Start: Modifications (Vadym Gryshchuk). f = h5py.File(args.out_file, 'r') dataset = f[args.layer_names][...] np.savetxt(args.out_features_file, dataset, delimiter=',') np.save print("Features are written also to: {}".format(args.out_features_file)) print("Done.")